Hi,
I'm trying to find a way to select a node with right-click before opening contextual menu.
Is this possible ?
Thanks for your help
hi,
You can try this code:
<ig:XamDataTree MouseRightButtonDown="XTree_MouseRightButtonDown" ItemsSource="{Binding Data}"> <ig:ContextMenuService.Manager> <ig:ContextMenuManager> <ig:ContextMenuManager.ContextMenu> <ig:XamContextMenu Opening="XamContextMenu_Opening" Opened="XamContextMenu_Opened"> <ig:XamMenuItem Header="Item 1" /> <ig:XamMenuItem Header="Item 2" /> </ig:XamContextMenu> </ig:ContextMenuManager.ContextMenu> </ig:ContextMenuManager> </ig:ContextMenuService.Manager> </ig:XamDataTree>
private XamDataTreeNodeControl clickedNode; private void XamContextMenu_Opening(object sender, OpeningEventArgs e) { var node = e.GetClickedElements<XamDataTreeNodeControl>().FirstOrDefault(); if (node != null && node.Node != null && node.Node.NodeLayout != null && node.Node.NodeLayout.Tree != null) { clickedNode = node; var selectedNodes = clickedNode.Node.NodeLayout.Tree.SelectionSettings.SelectedNodes; selectedNodes.Clear(); selectedNodes.Add(clickedNode.Node); return; } clickedNode = null; e.Cancel = true; } private void XamContextMenu_Opened(object sender, OpenedEventArgs e) { // TODO } private void XTree_MouseRightButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { XamDataTree dataTree = sender as XamDataTree; UIElement rootVis = Application.Current.RootVisual; if (dataTree != null && rootVis != null) { var nodeControl = VisualTreeHelper.FindElementsInHostCoordinates(e.GetPosition(rootVis), dataTree) .OfType<XamDataTreeNodeControl>() .FirstOrDefault(); if (nodeControl != null && nodeControl.Node != null) { nodeControl.Node.IsActive = true; } } }
Hope this helps
How would you do this if you were using WPF instead of Sliverlight?
Nikolay, that was exactly what I was searching for.
Thank you very much !