Tree view right click menu

Jul 19, 2011 at 11:35 AM

I have added a right click menu to my tree view control using xaml. The question is, how do I access a particular selected item that has been right clicked and remove it from the tree?


		<my:PopupMenu Name="RCM" RightClickElements="treeView" LeftClickElements="treeView" AccessShortcut="ctrl+alt+m">
                <my:PopupMenuItem Header="Add" ImageSource="images/add.jpg"></my:PopupMenuItem>
                <my:PopupMenuItem Header="Delete" ImageSource="images/delete.png"></my:PopupMenuItem>
                <my:PopupMenuItem Header="Refresh"></my:PopupMenuItem>



Jul 19, 2011 at 4:02 PM
        void Menu_RemoveItem(object sender, RoutedEventArgs e)

            TreeViewItem item = RCM.GetClickedElement<TreeViewItem>() as TreeViewItem;

The following event it being called but fails to remove an item from the tree.


Jul 20, 2011 at 2:28 AM
Edited Jul 20, 2011 at 2:35 AM

Are you binding your Treeview to a datasource or collection?

If this is the case remove the item directly from the underlying data instead and your treeview will then automatically follow. If you are not using an observable collection then you might need to reload the Treeview to see the difference.