How can xamDataTree node's image can be controlled by datatriggers based on a value from viewmodel and treenodes are always expanded?
Hello,
One way to achieve the functionality you are looking for, to control the XamDataTree node's image, is through the use of converter. You can bind to a property in the ViewModel (e.g. custom property IsActive) and change the Image source depending on this property's value. You can use the converter in the CollapsedIconTemplate and ExpandedIconTemplate.
For your second question, you can load the XamDataTree with all the Nodes expanded, by recursively iterating through them:
private void ExpandAllNodes(IEnumerable<XamDataTreeNode> nodes, bool isExpandNode) { foreach (var node in nodes) { node.IsExpanded = isExpandNode; ExpandAllNodes(node.Nodes, isExpandNode); } }
To illustrate all this I have prepared a sample application.
If you need further assistance concerning this matter, please let me know.
Thanks Nick for the explanation of both questions and attachments, however, I would like image of the node to be changing at run time with underline property value changes. Thats why I wanted to do it via data triggers rather than a set value converter? How can I create that trigger?
In order to achieve the functionality you are looking for - change the node's image at run time, you can change its path. Depending on your application's logic , you can replace the image at runtime. To illustrate this I have modified the previous example and added a button which on click will replace the parent Nodes' images.
Please find it as an attached sample.
Also please take a look at this question, where a similar topic has been discussed.
Thank you for attached sample.