How to set a viewmodel property when Property Trigger fires
I have a ListView with a View Model. The ItemsSource is a collection of
objects in the View Model. A property exists on the View Model for some
flag, IsFlagOn. I want to set that property in the View Model to True when
the ListViewItem detects a IsMouseOver. Other UI elements are then bound
to this same property so that the view changes as MouseOver is toggled.
How would I accomplish this in XAML?
I would imagine something like this (but this breaks):
<Style> <!-- on the ListViewItem -->
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="DataContext.IsFlagOn" Value="True" />
</Trigger>
</Style.Triggers>
</Style>
UPDATE:
The error is
Cannot resolve the Style Property 'IsFlagOn'. Verify that the owning type
is the Style's TargetType, or use Class.Property syntax to specify the
Property.
No comments:
Post a Comment