Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
360
Collapse/Hide Child elements when Parent visibility is Collapse.
posted

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

Parents
  • 34830
    Offline posted

    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,
    Andrew
    Associate Developer

    XamDataTreeHideNodeCase.zip
Reply Children