I want to make all check boxes selected by selecting check box names with "All of Above". the checkboxes are in a List box
<ListBox SelectionMode="Multiple" BorderThickness="0" ItemsSource="{Binding QuestionThreeSelection}" SelectedItem="{Binding QuestionThreeSelection}" Name="listBoxList" SelectionChanged="listBoxList_SelectionChanged">
<ListBox.InputBindings>
<KeyBinding Command="ApplicationCommands.SelectAll"
Modifiers="Ctrl"
Key="A" />
</ListBox.InputBindings>
<ListBox.ItemTemplate>
<DataTemplate>
<CheckBox Checked="CheckBox_Checked_1" Content="{Binding SourceName}" IsChecked="{Binding Path=IsSelected, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
back Code
private void CheckBox_Checked_1(object sender, RoutedEventArgs e)
{
var oo = listBoxList;
CheckBox cb = (CheckBox)sender;
//var w=e;
IEnumerable<AddSource> listallityem = ((IEnumerable<AddSource>)listBoxList.Items.SourceCollection).Where(r => r.IsSelected == false);
//IEnumerable<AddSource> listallityem1 = ((IEnumerable<AddSource>)listBoxList.Items.SourceCollection);
AddSource vv = cb.DataContext as AddSource;
if ((bool) cb.IsChecked)
{
}
if (vv.SourceName== "All of the above")
{
r = listBoxList.ItemsSource;
foreach (AddSource item in wer)
{
item.IsSelected = true; // false in case of unselect
}
}
}
Can someone suggest a method?
Aucun commentaire:
Enregistrer un commentaire