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

Adding node context menu with Hiearchical View Model

3 Answers 47 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Anne Lyon
Top achievements
Rank 1
Anne Lyon asked on 23 Sep 2010, 02:40 PM
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!


3 Answers, 1 is accepted

Sort by
0
Igor Macedo
Top achievements
Rank 2
answered on 24 Sep 2010, 06:01 PM
Hi Anne,

Try something like this:

RadContextMenu.SetContextMenu(myTreeNode, contMenu);

Regards

Igor
0
Anne Lyon
Top achievements
Rank 1
answered on 27 Sep 2010, 01:08 PM
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.
0
Tina Stancheva
Telerik team
answered on 28 Sep 2010, 04:56 PM
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
Tags
TreeView
Asked by
Anne Lyon
Top achievements
Rank 1
Answers by
Igor Macedo
Top achievements
Rank 2
Anne Lyon
Top achievements
Rank 1
Tina Stancheva
Telerik team
Share this question
or