Hi Team,
I am using XamDataTree to display hierarchical data in 4 levels.
I have a requirement where I should not be showing a particular data for a condition in level 2. This condition is based on one of a property in my TargetTypeName in level 2; if the condition is true I need to collapse (hide) the level and also the data in the child levels for that parent.
Is there a way to achieve this by coding in XAML. I do not want to add the property in all the child elements.
Thanks,
Srikanth V
Hello Srikanth,
You can achieve this by creating a style for the XamDataTreeNodeControl element. This element is the container that essentially wraps and displays a XamDataTreeNode in the XamDataTree, and its data context contains a reference to the underlying XamDataTreeNode via the Node property, and a reference to the underlying data item via the Data property.
Knowing this, if you have a property on your underlying data item that specifies a conditional piece of information, you can write a style for XamDataTreeNodeControl and use a DataTrigger to bind to this property that specifies that condition, or perhaps if it is just part of your displayed data, you can bind that as well by binding to Data.PropertyNameOnUnderlyingDataItem. If the DataTrigger's binding value returns a value that says that the node should be hidden, you can mark the Height and Width properties of the XamDataTreeNodeControl as 0. I recommend the Height and Width, as the Visibility property is internally managed.
I have attached a sample project to demonstrate the above. I hope this helps you.
Please let me know if you have any other questions or concerns on this matter.
Sincerely,AndrewAssociate Developer
Hi Andrew,
Thank you for the support and the sample project. I am still facing an issue, when the nodes are expanded.
As per my requirement, I have to show the tree in expanded mode at all the levels for which I am making use of the IsExpandedMemberPath property in the NodeLayout which is being set by a property in my class/model. (is there a better way of expanded the tree at all nodes??)
When the nodes are expanded the Parent gets hidden but the child nodes still show. I have made a few modification to your sample solution to replicate the scenario. Please find the attached sample project and observe the expanded parent node 1 (in the output window).
I am currently using V15.2.
Cheers,
Srikanth.
It appears that the modifications that you have made to the sample project include an IsExpandedMemberPath in which every child node has that property path set to "true." Doing this, the behavior that you are currently seeing is expected, as the nodes are still there, even if they are "hidden" by having their Height and Width properties set to 0.
I would recommend that to prevent the child nodes from being shown, that you ensure that if the data item is marked as hidden, then the IsExpandedMemberPath returns false. In the case of the sample project, if the IsVisible property returns false, then so should the IsExpandedMemberPath to prevent the child nodes from being shown.