I have the following XAML:
<ListView x:Name='debitOrderItems' ItemsSource='{Binding DebitOrderItems}'> <ListView.ItemTemplate> <DataTemplate> <CheckBox x:Name='checkbox' Content='{Binding}' IsChecked='{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListViewItem}}, Path=IsSelected}' /> </DataTemplate> </ListView.ItemTemplate> </ListView>
Binding a list of items works fine and I get a beautiful listview with checkboxes, but I would like to have them all selected immediately. There is a SelectAll() method on the ListView, but when can I call it? DataContextChanged does not work as I link it before I populat the DebitOrderItems on it.
You can do this in the Loaded event:
That said, I’d question your design. Normally you would have a view model for each item in the list, and you would bind the
IsCheckedproperty to a property on that view model.