I have a hierarchical treeview in WPF. I use http://marlongrech.wordpress.com/2008/12/13/attachedcommandbehavior-v2-aka-acb/ for eventbinding with the viewmodel.
When I doubleclick an item in the treeview, I always want to pass the root type as the commandparameter.
Example:
A
..B
….C
D
..E
When I click on ‘A’, ‘B’ or ‘C’ I want ‘A’ as commandparameter.
When I click on ‘D’ or ‘E’ I want ‘D’ as commandparameter.
This is what I have so far, this always sends the item clicked as commandparameter:
<Setter Property="acb:CommandBehavior.Event" Value="MouseDoubleClick"/>
<Setter Property="acb:CommandBehavior.Command" Value="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.SomeCommand}"/>
<Setter Property="acb:CommandBehavior.CommandParameter" Value="{Binding}"/>
I suppose I have to do binding with RelativeSource, I can’t figure it out..
Regards,
Michel
To my knowledge you cannot create a binding which is equivalent to the wanted expression, you might be better off passing the current item as parameter and finding the root node in the command code.