EventToCommandBehavior, treeview, context menu and MVVM

2 posts, 0 answers
  1. Randy Hompesch
    Randy Hompesch avatar
    148 posts
    Member since:
    Nov 2008

    Posted 11 Dec 2017 Link to this post


    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


  2. Stefan
    Stefan avatar
    1073 posts

    Posted 14 Dec 2017 Link to this post

    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.

    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.
Back to Top