Adding node context menu with Hiearchical View Model

4 posts, 0 answers
  1. Anne Lyon
    Anne Lyon avatar
    87 posts
    Member since:
    Jan 2010

    Posted 23 Sep 2010 Link to this post

    Hi,

    My TreeView is bound to a ObservableCollection<TreeNode>. Using a HierarchicaldataTemplate the ItemSource is bound to my collection's TreeNodeChildren.
    I want to bind a context meny to each node, and must do it in code as the context meny can be different for each node.

    But how do I bind the contect menu to the node when the node is a TreeNode and not a RadTreeViewItem?
    I cannot cast the current TreeNode to a RadTreeViewItem and hence cannot use the code:
    myRadTreeViewItem.SetValue(RadContextMenu.ContextMenuProperty, contMenu);
    as TreeNode doesn't have that functionality. I know how to bind properties, like isExpanded, between myTreeNode class and the TreeView, but how do I "bind" a command?

    So in code I want to add a new TreeNode to my bound TreeNodeChildren collection, then dynamically create a new context menu and attach this context menu to my newly created TreNode. How do I do that?

    Appreciate if somebody has an idea!


  2. Igor Macedo
    Igor Macedo avatar
    26 posts
    Member since:
    Jun 2012

    Posted 24 Sep 2010 Link to this post

    Hi Anne,

    Try something like this:

    RadContextMenu.SetContextMenu(myTreeNode, contMenu);

    Regards

    Igor
  3. DevCraft banner
  4. Anne Lyon
    Anne Lyon avatar
    87 posts
    Member since:
    Jan 2010

    Posted 27 Sep 2010 Link to this post

    Hi Igor,

    First of all I apologize this question has appeared so many times in the forum as I encountered a Telerik server error which made me believe the postings had been unsuccessful... Please remove duplicate postings if you like...

    If I try your solution:
    "RadCOntextMenu.SetContextMenu(myCurrentreeNode, contMenu)" I get a syntax error as it doesn't like myCurrentTreeNode as parameter. This is even if the parameter is of type TreeNode which the class my Obserable Collection bound to the treeView consists of.
  5. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 28 Sep 2010 Link to this post

    Hello Anne Lyon,

    Please take a look at the answer to your other thread here.

    Regards,
    Tina Stancheva
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top