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
85
Cannot display hierarchical data in xamDataTree with class inheritance involved
posted
Trying to display a hierarchy in xamDataTree based on the composite design pattern. Created base class Node which classes File and Folder inherit from. Folder has a list of Node objects since it can contain both File and Folder objects.
 
Having difficulty creating a NodeLayout to suit this requirement since it is dependent on TargetTypeName. Any suggestion on how to do this?
 
            <ig:XamDataTree.GlobalNodeLayouts>
                <ig:NodeLayout Key="Test"
                               DisplayMemberPath="Text"
                               TargetTypeName="Node">
                    <ig:NodeLayout.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal">
                                <Ellipse Name="statusIndicator"                                                         
                                         Fill="Orchid"
                                         Height="15"
                                         Width="10"
                                         Stroke="#FF3D3DBE"
                                         StrokeThickness="1"/>
                                <TextBlock Name="itemTextBlock"
                                           Text="{Binding Data.Text}"
                                           TextAlignment="Left"
                                           HorizontalAlignment="Left"
                                           FontSize="11"
                                           VerticalAlignment="Center"/>
                            </StackPanel>
                        </DataTemplate>
                    </ig:NodeLayout.ItemTemplate>
                </ig:NodeLayout>
            </ig:XamDataTree.GlobalNodeLayouts>
 
Not able to display the children because expanders are not shown regardless of whether Node or Folder are used as the TargetTypeName.
 

Using TargetTypeName="Node" uses the ItemTemplate and outputs the ff

Using TargetTypeName="Folder" which contains the Children property is even worse
 
Class definitions are as follows:
    public class Node : INotifyPropertyChanged
    {
        private string text;
 
        public event PropertyChangedEventHandler PropertyChanged;
 
        protected void RaisePropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
 
        public string Text
        {
            get { return text; }
            set
            {
                if (text != value)
                {
                    text = value;
                    RaisePropertyChanged("Text");
                }
            }
        }
    }
 
    public class Folder : Node
    {
        private ObservableCollection<Node> children;
 
        public ObservableCollection<Node> Children
        {
            get { return children; }
            set
            {
                if (children != value)
                {
                    children = value;
                    this.RaisePropertyChanged("Children");
                }
            }
        }
    }
 
    public class File : Node
    {
    }
Parents
  • 14517
    Offline posted

    Hello,

    You can create a Node Layout for both the TargetTypeName =  Folder and one for the TargetTypeName = Node then it will create the Nodes based underlying type od the data.  Please see attached sample.

    Let me know if you have any questions.

    Valerie

    Composite.zip
Reply Children