I have a bunch of checkboxes in a grid. I have two buttons, a 'check all' button and a 'uncheck all' button. The names speak for themselves, but when I click the 'check all' button, all the checkboxes should be checked. When I click the 'uncheck all' button, all the checkboxes should be unchecked.
Now, I can make a command to loop through each checkbox and check/uncheck them for the buttons, but I was wondering if there was a simpler way using some binding. For instance, I tried this:
In the xaml:
<Grid>
<CheckBox Grid.Row="1"
Grid.Column="2"
IsChecked="{Binding IsChecked}" />
<CheckBox Grid.Row="2"
Grid.Column="2"
IsChecked="{Binding IsChecked}"/>
</Grid>
In my view model:
private bool _isChecked;
public bool IsChecked
{
get { return _isChecked; }
set { _isChecked = value; OnPropertyChanged("IsChecked"); }
}
The above doesn't work though, since ALL the checkboxes are bound to the same bool. So checking/unchecking one does the the same to all of them. But I'd like to do something like that. Is there something I'm not thinking of, or is the main way to just loop through them all?
Aucun commentaire:
Enregistrer un commentaire