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

Possible ContextMenu Bug

4 Answers 59 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Seth
Top achievements
Rank 1
Seth asked on 18 Jun 2009, 01:36 PM
I have tried implementing the Silverlight ContextMenu on a series of dynamically created Telerik Treeview objects.  Ideally, when the user right clicks, the current node should become selected so that when they select an item from the menu, it will only apply to the currently selected node.

As it is now, when the user right clicks on a node, the ContextMenu does show up, however that node does not automatically become selected.  I implemented the Mouse.AddMouseUpHandler(this, OnRightMouseButtonUp); code that was specified in the example, but this has not worked, possibly because the treeviews are created dynamically.

Please advise.

Thanks,
Seth

4 Answers, 1 is accepted

Sort by
0
Valeri Hristov
Telerik team
answered on 19 Jun 2009, 10:59 AM

Hi Seth,

To achieve the desired functionality you may check my blog post about putting a context menu on a tree view:
http://blogs.telerik.com/valerihristov/posts/09-06-01/reusing_and_customizing_a_single_contextmenu_on_a_treeview_with_radcontrols_for_silverlight.aspx

and add the highlighted line in the following method:
private void ContextMenuOpened(object sender, RoutedEventArgs e)
{
 this.ClickedTreeViewItem.IsSelected = true;

 DataItem dataItem = this.ClickedTreeViewItem.DataContext as DataItem;

 // We will disable the "New Sibling" and "Delete" context menu
 // items if the clicked treeview item is a root item
 bool isRootItem = dataItem.Parent == null;

 (this.ContextMenu.Items[1] as RadMenuItem).IsEnabled = !isRootItem; // New Sibling
 (this.ContextMenu.Items[2] as RadMenuItem).IsEnabled = !isRootItem; // Delete
}

Best wishes,

Valeri Hristov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Seth
Top achievements
Rank 1
answered on 24 Jun 2009, 08:23 PM
I'm not able to get the example to compile.  There is an error on getting MousePosition from the context menu.  Is this going to be part of the Q2 build for the Telerik Silverlight controls?

Thanks,
Seth
0
Accepted
Valeri Hristov
Telerik team
answered on 25 Jun 2009, 07:52 AM
Hi Seth,

Yes, this property is going to be included in the Q2, but it is also available in the latest internal builds:
http://www.telerik.com/account/downloads/internal-builds.aspx

All the best,
Valeri Hristov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Seth
Top achievements
Rank 1
answered on 25 Jun 2009, 02:50 PM
Thanks Valeri, the ContextMenus will be a major part of my project.

--Seth
Tags
General Discussions
Asked by
Seth
Top achievements
Rank 1
Answers by
Valeri Hristov
Telerik team
Seth
Top achievements
Rank 1
Share this question
or