Telerik Forums
UI for Silverlight Forum
0 answers
70 views

We have a context menu that has ContextMenuItem(s) which are connected to commands which take as a parameter the particular tree item the context menu was called on. In other words, if I right click on a particular tree item specifically, some of the ContextMenuItems have functionality which derives from that selected tree item's properties.

So we would like to be able to open the context menu of our treeview as though it was opened by right clicking a particular item in a rad tree view.

Our RadContextMenu is not nested inside of the treeviewitems as in the following solution:

https://www.telerik.com/forums/show-context-menu-for-tree-view-from-keyboard-shows-silverlight-menu-also

 

The context menu is nested inside of the treeview itself, and the treeitem parameters are passed in using the following XAML:

<telerik:RadMenuItem Header="Assign Write All Modules"
                                             Command="{Binding Path=ViewModel.OurCommand}"
                                             CommandParameter="{Binding RelativeSource={RelativeSource                                                                                          Self}}">
                                                    <telerik:RadMenuItem.Icon>
                                                        <Image
                                Source="OurImage.png"
                                Width="16" Height="16" />

 

Sorry it's messy. The web-code-formatter wasn't working quite right.

When right clicking, everything works fine, so I don't intend to change the way this is done unless I have to. 

How can I play with the ContextMenu to be able to do this?

I have tried this:

RadTreeView tree = sender as RadTreeView;
RadContextMenu.SetContextMenu(tree.SelectedContainer, RadContextMenu.GetContextMenu(tree));
var menu1 = RadContextMenu.GetContextMenu(tree.SelectedContainer);
if (menu1 != null)
{
    menu1.PlacementTarget = tree.SelectedContainer;
    menu1.InheritDataContext = true;
    menu1.IsOpen = true;
    e.Handled = true;
}

 

but that just opens the context menu of the treeview, of course. When I select the menu items that consume a treeitem as a parameter, the functions attached to my command do not receive the treeitem. I saw in the library that there is a "UIElement" property and an "elementCausedContextMenuOpen" property. I was thinking that with the way we have our XAML implemented, we could simply set one of these parameters. I started to look into it, but these parameters are both private, which led me to believe I will have to get some guidance from you guys on this.

What seems like the most simple way to go about this?

Matthew
Top achievements
Rank 1
 asked on 23 Apr 2020
Top users last month
Dominik
Top achievements
Rank 1
Giuliano
Top achievements
Rank 1
Dominic
Top achievements
Rank 1
Glendys
Top achievements
Rank 1
Iron
NoobMaster
Top achievements
Rank 2
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?