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.6K RobotStudio
 - 401 UpFeed
 - 21 Tutorials
 - 15 RobotApps
 - 306 PowerPacs
 - 407 RobotStudio S4
 - 1.8K Developer Tools
 - 250 ScreenMaker
 - 2.9K Robot Controller
 - 363 IRC5
 - 81 OmniCore
 - 8 RCS (Realistic Controller Simulation)
 - 853 RAPID Programming
 - 31 AppStudio
 - 4 RobotStudio AR Viewer
 - 19 Wizard Easy Programming
 - 110 Collaborative Robots
 - 5 Job listings
 
