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?
that´s exactly what I´d like to know as well.
How can this be done using the WPF type of XamDataTree (v13.1) ???
Daniel
Hello Daniel,
Thank you for your post. I have been looking into it and I created a sample project with the same functionality Nikolay achieved, but in WPF. Basically instead of using VisualTreeHelper’s FindElementsInHostCoordinates method, which is not available in WPF, I used the Infragistics Utilities class and the GetAncestorFromType method to get the clicked node. Please let me know if this helps you or you need further assistance on this matter.
Looking forward for your reply.
Hello Stefan,
Thank you for your post. I have been looking into it and I created a sample project with the same functionality...
...unfortunately I cannot open the project because it is incompatible with my version of Visual Studio (2010).Anyway, I found a solution meanwhile which solves my problem.
Thanks for reopening this issue.
Daniel,
FYI: if you can't open a project in visual studio, you can still examine the source code using a text editor, such as notepad, or my personal favorite editor-of-last-resort, notepad++