This treeview class works differently from the windows forms class. Every example I see to change selected node uses items.selectednode or nodes.selectednode. However, I am struggling to find a method of doing this for this class: https://msdn.microsoft.com/en-us/library/system.windows.controls.treeview(v=vs.110).aspx
Asked
Active
Viewed 394 times
0
-
duplicate with this post : https://stackoverflow.com/questions/413890/how-to-programmatically-select-an-item-in-a-wpf-treeview – Oilid May 11 '18 at 09:21
-
Might be duplicate. But noone seems to know how to do a rigclick select node on WPF treeview – PigSpider May 11 '18 at 10:26
-
Right-click? What do you want to exaclty and what have you tried so far? – mm8 May 11 '18 at 14:44
1 Answers
0
I wanted to enable right click to popup my context menu. Could not find another solution, so here's what I did, and it works:
private void TreeSetup_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
((TreeViewItem)sender).IsSelected = true;
e.Handled = true;
}
private void TreeSetup_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
{
ContextMenu PopupMenu = this.FindResource("cmButton") as ContextMenu;
if (TreeSetup.SelectedItem != null)
{
PopupMenu.PlacementTarget = sender as TreeViewItem;
PopupMenu.IsOpen = true;
}
}

PigSpider
- 881
- 9
- 18