Create ContextMenu of WpfTreeView
Hi everybody.
I want to build some sort of browser window using the WpfTreeView. My problem now is, that I wnat to add a ContextMenu (Right click) to the Items, just like the Menus in e.g. the Layout browser. I added a context menu in the .xaml of the usercontrol, but I want to show the ContextMenu only on the childnodes of my rootnode.
So how can I add the Menu only to the childnodes and not to the whole treeview?
I want to build some sort of browser window using the WpfTreeView. My problem now is, that I wnat to add a ContextMenu (Right click) to the Items, just like the Menus in e.g. the Layout browser. I added a context menu in the .xaml of the usercontrol, but I want to show the ContextMenu only on the childnodes of my rootnode.
So how can I add the Menu only to the childnodes and not to the whole treeview?
<div><rs:WpfTreeView.ContextMenu></div><div> <ContextMenu Background="WhiteSmoke"></div><div> <MenuItem Header="Remove" Click="ContextMenuRemove_Click"/></div><div> </ContextMenu></div><div></rs:WpfTreeView.ContextMenu></div>
0
Best Answer
-
I don't think it's possible to do completely in XAML.
But you could subscribe to the right-click event and display a context menu depending on what is selected. Something like this: private void _treeView_MouseRightButtonUp(object sender, MouseButtonEventArgs e)<br> {<br> if (_treeModel.SelectedNodes.Count() == 1) // Or whatever condition<br> {<br> var ctxMenu = this.FindResource("_ctxMenu1") as ContextMenu;<br> ctxMenu.IsOpen = true;<br> }<br> }<br>
Johannes Weiman
Software Engineer
RobotStudio Team, ABB Robotics5
Answers
-
Okay. Just thought their would be a better or more elegant way than that. But than I will make it like this. Thank you.0
Categories
- All Categories
- 5.5K RobotStudio
- 395 UpFeed
- 18 Tutorials
- 13 RobotApps
- 297 PowerPacs
- 405 RobotStudio S4
- 1.8K Developer Tools
- 249 ScreenMaker
- 2.7K Robot Controller
- 310 IRC5
- 59 OmniCore
- 7 RCS (Realistic Controller Simulation)
- 785 RAPID Programming
- AppStudio
- 3 RobotStudio AR Viewer
- 18 Wizard Easy Programming
- 105 Collaborative Robots
- 4 Job listings