上午使用列表框項目中的複選框,如何選中和取消選中列表框中的所有複選框?如何選中和取消選中列表框中的已選框項目?
<ListBox Height="168" HorizontalAlignment="Left" Margin="45,90,0,0" Name="listBox1" VerticalAlignment="Top" Width="120">
<ListBox.ItemTemplate>
<DataTemplate>
<CheckBox Content="{Binding Name}" IsChecked="{Binding Ck, Mode=TwoWay}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
數據綁定是:
List<uu> xx = new List<uu>();
xx.Add(new uu { Name = "A", Ck = false });
xx.Add(new uu { Name = "A", Ck = false });
listBox1.ItemsSource = xx;
更新:
是否有可能做這樣的事情:
foreach (ListBoxItem item in listBox1.Items)
{
CheckBox ch = (CheckBox)item;
ch.IsChecked = true;
}
*設置* ItemsSource不完全是數據綁定。 –