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
240
XamDataTree with no expander/collapse icon and removing/adding an child node dynamically with MVVM
posted

Hi,

I need to make XamDataTree with no expander and collapse icons and should always be in expandable state. Child nodes should add/remove dynamically at run time. This has to be implemented through MVVM.

Child node should be displayed with "Close" button so when user click on close button we should remove the child node.

When we select the child node, it should display the content at the right pane. No Selection should be made for root node (i.e. selection should be enabled only for child nodes).

Thanks and Regards,

Shashikanth N.

Parents
No Data
Reply
  • 16495
    Offline posted

    Hello Shashikanth ,

    To expand all nodes you can create a recursive  method which iterates though the nodes and set XamDataTreeNode's IsExpanded property to true, this way in the same method you can access the expansion button and set it's Visibility property to false, for example:

     
    private void SetNodeExpandedState(IEnumerable<XamDataTreeNode> nodes, bool expandNode)
     {
         foreach (XamDataTreeNode item in nodes)
         {
             item.IsExpanded = expandNode;

             Application.Current.Dispatcher.BeginInvoke(new Action(() =>
             {
                 var expBtn = Infragistics.Windows.Utilities.GetDescendantFromType(item.Control, typeof(ExpansionIndicator), true) as ExpansionIndicator;
                 if (null != expBtn)
                     expBtn.Visibility = Visibility.Collapsed;
             }), System.Windows.Threading.DispatcherPriority.SystemIdle);
            
             this.SetNodeExpandedState(item.Nodes, expandNode);
         }
     }

    You can use XamDataTree's Loaded event to call SetNodeExpandedState method. To handle it in your view model you can use Interaction:
     
     <i:Interaction.Triggers>
         <i:EventTrigger EventName="Loaded" SourceName="xdt">
             <ei:CallMethodAction MethodName="XamDataTree_Loaded" TargetObject="{StaticResource vm}" />
         </i:EventTrigger>
     </i:Interaction.Triggers>

    By creating an ExpandedIconTemplate for the child layout you can add the 'Close' button you wish. Additional details are available on Configuring Expanded/Collapsed Node State topic.

    From the following forum thread you can see how to update XamDataTree's ItemSource at runtime:

    https://ko.infragistics.com/community/forums/t/74343.aspx

    From Configuring Selected Data Items topic you can see an example of how XamDataTree SelectedDataItems property is used as an ItemsSource of the ListView control.

    I have attached a simple sample application. You can use it as a starting point for implementing the functionalities you are trying to achieve. It will be great if you create a separate thread for each of your questions next time, this way the communication would be easier and there would be no confusion about the issues. Also other community members that have similar issues would be able to benefit from the threads too.

    Let me know if you have any questions.

    Sincerely,
    Zhivko
    Associate Software Developer

    XDT_project.zip
Children