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?
Hello Prasanti,
Thank you for your post. I have been looking into it and I can suggest you see the sample in the Samples Browser under xamDataTree / Display / Node Layout section where it is shown how to define node layouts. Under xamDataTree / Display / NodeLines section you can see how to add images to the nodes.
Hopes this helps you.
Hi Stefan,
I have tried a sample on XamDataTree which is binded to my collection having two entities, namely Categories and Products. I tried to include a datatemplate in nodelayout to display an image followed by textblock for a node . But I failed to do it. I have declared an interface called Node, with Name and children(Collection of Node) as its members and my Category and Product classes are inherited from the Node interface. In Category class, I have set Children to Collection of Products and In Product I have set children to null. And I have set the name property to their respective names.
The Problem I am facing is:
I could not see any Product List under each Category. All I could display is a list of categories.
My DataTemplate is
<ig:NodeLayout.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Data.Text}">
</DataTemplate>
</ig:NodeLayout.ItemTemplate>
Kindly help me in this issue.
Thankyou,
Prasanti
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++
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.
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.