TreeViewItem and DelegateCommand

Topics: Prism v4 - WPF 4
Jul 16, 2011 at 5:47 PM
Edited Jul 17, 2011 at 5:48 PM

I have seen a couple of posts on this but I have not seen an answer to the problem.  I would like to attach a DelegateCommand to a TreeViewItem.  I tried the following but it does not seem to work. It says that "Property Command in not attachable to elements of type 'TreeViewItem'"

<TreeViewItem Header="Test" FontWeight="Normal" prism:Click.Command="{Binding ShowCommand}"></TreeViewItem>
After reading the prism documentation it says that the Click.Command is only for controls that derive from ButtonBase.  
Hence, that is why the above XAML does not work.  After further reading it says that I can inherit from the CommandBehaviorBase 
to add command behavior to other controls.  I have a simple treeview with two parents and three children under each parent.  I want to use
a viewmodel to bind to each treeviewitem to find which child was selected and what the parent name is.  What is the best way to accomplish this?
Should I still use the CommandBehaviorBase?  BTW, this is a WPF application with prism 4.0.
Jul 18, 2011 at 12:40 PM
Edited Jul 18, 2011 at 12:40 PM


Based on my understanding on your scenario, you could try using the CommandBehaviorBase to create a custom command behavior that applies to the TreeViewItem's click action.

I hope you find this helpful.

Guido Leandro Maliandi