Reputation: 11130
I have a ListBox
defined as follows. I have CheckBox
inside the ListView
item which needs to be checked/unchecked programmatically (just wanted to implement a select/deselect all operation). What's the best way to achieve this?
<ListBox Margin="0,0,10,0" Name="listViewChanges" SelectionMode="Multiple">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
<CheckBox x:Name="lblChangedSelected" IsChecked="{Binding Selected}" VerticalAlignment="Center" VerticalContentAlignment="Center" Margin="10,0,0,0"></CheckBox>
<Label x:Name="lblChangedStatus" Content="{Binding Status}" VerticalContentAlignment="Center"></Label>
<Label x:Name="lblChangedPath" Content="{Binding Path}" VerticalContentAlignment="Center"></Label>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Upvotes: 0
Views: 285
Reputation: 56697
You should have the class that's behind the binding implement INotifyPropertyChanged
. Then, when you change the property, fire the NotifyPropertyChanged
event and the binding should update automatically.
Upvotes: 2