This is a migrated thread and some comments may be shown as answers.

EventToCommandBehavior, treeview, context menu and MVVM

1 Answer 214 Views
ContextMenu
This is a migrated thread and some comments may be shown as answers.
Randy Hompesch
Top achievements
Rank 1
Randy Hompesch asked on 11 Dec 2017, 04:46 PM

Ok,

I have a treeview that is LoadOnDemand. I have a HierarchicalDataTemplate and within it I define a RadContextMenu.

Currently, I am setting the ItemClicked event handler and calling the ViewModel from code behind. It all works, but I know I am being a bad boy calling the viewmodel from the codebehind. 

 

Here's what I'd like to do: 

Somehow, bind a command to the HierachicalDataTemplate so that I have a single function that receives all context menu clicks via a command. I should be able to sort out which context menu item was clicked in the command parameter (I think).

I have tried adding an EventToCommandBehavior to the HierachicalDataTemplate, but the compiler whines that nested properties are not supported.

I get this because I am already using EventToCommandBehavior in the treeview itself.

It seems that putting an additional EventToCommandBehavior in the HierarchicalDataTemplate is a no-go.

How can I receive commands from context menus generated in a loadondemand treeview and have it be MVVM friendly?

Thanks ... Ed

 

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 14 Dec 2017, 09:51 AM
Hi Ed,

I tested the behavior of the control and I am able to define two usages of the EventToCommandBehavior within a similar setup on my end. Can you please take a look at the attached example? Note, that I have used the Add Context Menu SDK Example for testing. Would it be possible to demonstrate your setup in the project and send it back to me, so I can assist you further?

Thanks in advance for your cooperation.

Regards,
Stefan
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
ContextMenu
Asked by
Randy Hompesch
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or