0
一直试图弄清楚,我如何捕获列表框中的事件。在模板中,我添加了参数IsChecked =“”,它启动了我的方法。但是,问题是试图捕获方法中检查的内容。 SelectedItem只返回当前选中的内容,而不是复选框。捕获WPF Listbox复选框选择
object selected = thelistbox.SelectedItem;
DataRow row = ((DataRowView)selected).Row;
string teststring = row.ItemArray[0].ToString(); // Doesn't return the checkbox!
<ListBox IsSynchronizedWithCurrentItem="True" Name="thelistbox" ItemsSource="{Binding mybinding}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<CheckBox Content="{Binding personname}" Checked="CheckBox_Checked" Name="thecheckbox"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
感谢这个!最后一种方法效果很好。想到使用你所描述的第二种方式,但是我的UI仍处于不断变化的状态。 – wonea 2010-05-17 09:11:16