Make TreeViewItem control execute command when double clicked
-
29-10-2019 - |
Question
I'm looking for a way, in WPF, to bind commands to a TreeViewItem, so when I double click a TreeViewItem a ICommand is executed in my ViewModel (MVVM pattern). Much like the Visual Studio Solution Explorer.
I was hoping that I could use something like AttachedCommandBehaviour but that does not work. I guess it's because that the TreeViewItem itself does not support Commands.
Here is my test implementation which doesn't work:
<TreeViewItem Header="Opret produktions ordre">
<acb:CommandBehaviorCollection.Behaviors>
<acb:BehaviorBinding Event="MouseLeftButtonDown" Command="{Binding TestCommand}"/>
</acb:CommandBehaviorCollection.Behaviors>
</TreeViewItem>
Does anyone have a suggestion on how to make this work? Or maybe you know of a control that give me this functionality? I am of course hoping for a MVVM friendly solution. Preferably all in XAML.
No correct solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow