I have a check box which I plan to implement a 'Select All' feature on.
I figured the easiest implementation was to modify my DataTemplate with a DataTrigger to change the IsChecked property to true/false.
<UserControl.Resources>
<DataTemplate x:Key="MyTemplate">
<Grid>
<CheckBox x:Name="Selection" IsChecked="{Binding Selected}" />
</Grid>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding ElementName=SelectAll, Path=IsChecked}" Value="true">
<Setter TargetName="Selection" Property="DataContext.Selected" Value="true" />
</DataTrigger>
<DataTrigger Binding="{Binding ElementName=SelectAll, Path=IsChecked}" Value="false">
<Setter TargetName="Selection" Property="IsChecked" Value="false" />
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</UserControl.Resources>
<Grid>
<CheckBox Name="SelectAll />
<ListView Name="lvSteps" ItemTemplate="{StaticResource MyTemplate}" ItemsSource="{Binding MyList}" />
</Grid>
However, this overwrites the binding of the CheckBox which is set to the DataContext property 'Selected' to just the bool values set in the DataTrigger.
Which thinking about it makes perfect sense.
So my question is, can I change the value of DataContext property within a DataTrigger via Setter?
So I can keep my CheckBox bound to 'Selected', and change the 'Selected' value within the Setter of the DataTrigger?