I have two questions:
1) Can the ActiveDataItem property of the XamDataTree be bound to a property in the viewmodel
2) At the moment I'm setting the active node setting the ActiveDataItem property from code behind, but I haven't found the something like a Selected Node, or selected data item or something to allow me to activate and select a node on the tree from code behind or using the view model.
changing the active data item puts the active border around a node and makes it visible if it was not before but when the node is clicked it is not only activated but also selected.
is there a way to achieve this using the view model or the code behind.
Also, is it possible somehow access the Tree Node connected to the active data item?
thank you in advance
Hello Sabrina,
Thank you for your post.
1. Yes, the ActiveDataItem property of the XamDataTree is a dependency property, and so it can be bound to a ViewModel property.
2. The XamDataTree has a SelectedDataItems property that accepts bindings from an object array. If you initialize this array as a property in your ViewModel and add an item from your data source to it, it will be selected on startup if bound. The same goes for the ActiveDataItem. You will need to bind it to an item in your bound data source.
Regarding obtaining the tree node connected to the active data item, you cannot obtain it from the data item directly, but the XamDataTree has an ActiveNode property that you can use. It also has ActiveNodeChanging / ActiveNodeChanged events that you can handle to obtain this node from code.
I have attached a sample application to demonstrate the above.
Please let me know if you have any other questions or concerns on this matter.
Sincerely,AndrewAssociate DeveloperInfragistics Inc.www.infragistics.com/support
Just checking in, did you have any other questions or concerns on this matter?
SincerelyAndrewAssociate DeveloperInfragistics Inc.www.infragistics.com/support
Hi Andrew,
I have the following question,
I've modified my User control with the tree so that clicking with the Right mouse button automatically activates the underneath node
this is due to the fact that the context menu gives various options to the user and they expect that the commands work on the clicked node
without having to first select it and then right click it.
The node is highlighted which is fine; but even if I've managed to use your solution to my previous question adding the SelectedDataItems array and the node data is correctly inside the array, the element on the tree has not the same background as when it is left clicked on the tree (I use the tree without any change to the visualization style) Is there something I have to set in the tree to communicate it to set the selected item style to the tree node?
I've enclosed a zip file with two screenshots to better explain what I need.
I apologize for the delay in my response.
The XamDataTree nodes have two different visual states. One for Active and another for Selected. In this case, I would recommend writing a Style for XamDataTreeNodeControl and using an EventSetter to hook into the PreviewMouseRightButtonDown event. In the event handler, cast the sender to a XamDataTreeNodeControl, and call nodeControl.Node.IsActive and nodeControl.Node.IsSelected to apply both visual styles to the XamDataTree node. This will also happen just before the context menu opens.
I hope this helps you. Please let me know if you have any other questions or concerns on this matter.
Maybe the Style can be a solution but working with Codebehind for me is easier, so I found that I was able to change the selection using the
nodeControl.Node.IsSelected = true;
in the MouseUp event of the tree node I used for the context menu managementand I've been able to find the GetNodesFromItems method given by the XamDataTree control that allowed me to set the IsSelected property of the nodegetting it from the Data information it contains.
Just so that if someone else needs this
bye