I can trigger property settings on my ListBoxItem template based on properties of underlying data object using DataTrigger with something like this
<DataTrigger Binding='{Binding Path=IsMouseOver}' Value='true'> <Setter TargetName='ItemText' Property='TextBlock.TextDecorations' Value='Underline'> </Setter> </DataTrigger>
But what if I want to do the opposite? I mean set a property value on the underlying data object based on property value of my ListBoxItem. Something like:
<Trigger Property='IsMouseOver' Value='True'> <Setter Property='MyClass.IsHilited' Value='True'></Setter> </Trigger>
Is there a mechanism for something like this or what would be the recommended approach to deal with situations like this?
Thanks.
I think that you could use an EventSetter to do in XAML what Josh G suggested in code. Maybe create one for the
MouseEnterandMouseLeaveevents, and style the control appropriately for each?Update: You can set up the events like this:
The Style registers for the
MouseEnterandMouseLeaveevents for allListBoxItemsdefined in thatListBox.And then in your code behind file:
These handlers set the color of the text of the
ListBoxItemto red when the mouse is over the item, and back to black when the mouse leaves it.