Johan
Johan

Reputation: 512

MVVM-Light EventToCommand in Style

I have a standard WPF TreeView control. The TreeViewItem has a Arrow that rotates if one expand the TreeViewItem node.

The TreeView sets the highlight to the collapsed node by default if one of its children was selected. I have managed to make sure that the SelectedItem on my VM does not update when one collapse a node even though the selection graphics in the control would jump to that Node if one of the children was selected before. (I solved that by binding MouseUp event on TreeView to a command on my VM rather than using the SelectedItemChanged, I provide the SelectedItem as commandaparameter, that way the SelectedItem on my VM will not change unless the user really clicks a node)

The problem is that when one expand the collapsed Node again using the arrow, I would like the selection highlight to jump back to the child again, which really is the item in my collection on the VM that has its property IsSelected set to true.

If I could just trigger a command on my VM on MouseDown or when the ToggleButton gets checked I could likely solve this.

The problem is, I don't find a way to force the MouseDown event on the TreeView's ToggleButton to trigger a command on my VM by applying it in a style. Is it possible? if so how can one accomplish it. I use MVVM-Light so preferably I would like to use EventToCommand, but that does not seem to work at all from within a Style?

What I would like to do...(and have it affect the ToggleButton in the TreeView)

 <Style TargetType="{x:Type ToggleButton}">
 <i:Interaction.Triggers>
   <i:EventTrigger EventName="MouseDown">
     <command:EventToCommand Command="{Binding UpdateTreeState}"/>
   </i:EventTrigger>
  </i:Interaction.Triggers>
 </Style>

Upvotes: 1

Views: 67

Answers (0)

Related Questions