Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8959151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:22:48+00:00 2026-06-15T15:22:48+00:00

I have an object with this structure public class Parent { public string Name

  • 0

I have an object with this structure

public class Parent
{
  public string Name {get; set;}
  public int ID {get; set;}
  public List<Child> Children{set; get;}
  public Address HomeAddress {get; set;}
}

I created a hierarchical template for Address, Parent, Children with the ObjectToObservableListConverter

 public class ObjectToObservableListConverter : IValueConverter
    {

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value != null)
            {
                return new ObservableCollection<Graphic> { (value as Graphic) };
            }
            return null;
        }


        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }    

    }

and PropertyToListConverter

public class PropertyToListConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            Type type = value.GetType();
            PropertyInfo[] propertyList = value.GetType().GetProperties();
            List<object> values =
                (from property in propertyList
                 //where property.GetCustomAttributes(typeof(NotForTreeViewAttribute), false).Count() == 0
                 select property.GetValue(value, BindingFlags.Default, null, null, CultureInfo.InvariantCulture)).ToList();
            return values;

        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

The templates I created are:

 <TreeView  ItemsSource="{Binding Path=Parent,
                                            Converter={StaticResource ResourceKey=objectToListConverter},
                                            UpdateSourceTrigger=PropertyChanged}">
            <TreeView.Resources>

    <HierarchicalDataTemplate DataType="{x:Type en:Parent}"
                                                  ItemsSource="{Binding Path=Children}">
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Margin="0,4,0,0"
                                           VerticalAlignment="Center"
                                           FontWeight="Bold"
                                           Text="Children" />
                        </StackPanel>
                    </HierarchicalDataTemplate>
                    <HierarchicalDataTemplate DataType="{x:Type en:Child}"
                                                  ItemsSource="{Binding Converter={StaticResource ResourceKey=propertyToListConvertor}}">
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Margin="0,4,0,0"
                                           VerticalAlignment="Center"
                                           FontWeight="Bold"
                                           Text="{Binding Path=ChildName}" />
                        </StackPanel>
                    </HierarchicalDataTemplate>
                    <HierarchicalDataTemplate DataType="{x:Type en:Address}"
                                                  ItemsSource="{Binding Converter={StaticResource ResourceKey=propertyToListConvertor}}">
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Margin="0,4,0,0"
                                           VerticalAlignment="Center"
                                           FontWeight="Bold"
                                           Text="AddressType" />
                        </StackPanel>
                    </HierarchicalDataTemplate>

</TreeView.Resources>
</TreeView>

If I create the template on Parent
and set the ItemsSource Path of the Children Property, I don’t Get the remaining properties of Parent.
Or
If I set the ItemsSource as the property of type Parent and user property to list converter i dont get hierarchy of children.

What am I missing?

Please help. Thanks in Advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T15:22:49+00:00Added an answer on June 15, 2026 at 3:22 pm

    I found the solution to the problem.

    I changed my converter to set the list property to another custom class which contains only one property of list type and wrote a hierarchical data template for the same.

    PropertyToListConverter

      public class PropertyToListConverter : IValueConverter
            {
                public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
                {
                    Type type = value.GetType();
                    PropertyInfo[] propertyList = value.GetType().GetProperties();
                    List<object> values =
                        (from property in propertyList
                         select GetValueOrElementName(value, property)).ToList();
                    return values;
    
                }
    
                private static object GetValueOrElementName(object value, PropertyInfo property)
                {
                    var propVal = property.GetValue(value, BindingFlags.Default, null, null, CultureInfo.InvariantCulture);
    
                    if (property.PropertyType.IsGenericType && propVal != null)
                    {
                        Type type = property.PropertyType.GetGenericArguments().FirstOrDefault();
                        if (type == typeof(Child))
                            return new EnumerableClass() { Children = propVal as List<Child> };                   
                    }
    
                    if (propVal != null && !string.IsNullOrEmpty(propVal.ToString()))
                        return propVal;
    
    
                    return "Property["+ property.Name+"]";
    
                }
    
    
                public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
                {
                    throw new NotImplementedException();
                }
            }
    

    CustomClass

     public class EnumerableClass
        {        
            public string Name { get; set; }
            public List<Child> Children
            {
                get;
                set;
            }        
        }
    

    Hierarchical Data template

    <HierarchicalDataTemplate DataType="{x:Type en:Parent}"
                                                  ItemsSource="{Binding Converter={StaticResource ResourceKey=propertyToListConvertor}}">
                        <StackPanel Orientation="Horizontal">                        
                            <TextBlock Margin="0,4,0,0"
                                           VerticalAlignment="Center"
                                           FontWeight="Bold"
                                           Text="{Binding Path=ParentName}" />
                        </StackPanel>
                    </HierarchicalDataTemplate>
                    <HierarchicalDataTemplate DataType="{x:Type ap:EnumerableClass}"
                                                  ItemsSource="{Binding Path=Children,UpdateSourceTrigger=PropertyChanged}">
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Margin="0,4,0,0"
                                           VerticalAlignment="Center"
                                           FontWeight="Bold"
                                           Text="Children" />
                        </StackPanel>
                    </HierarchicalDataTemplate>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have this structure: public class Parent { public string Name{get; set;} public
If I have this structure: public class Parent { public string Name{get; set;} public
I have a object structure like this: public class Entity { IList<Relationship> Relationships{get;set;} }
I have the following structure: class foo(object): class bar(object): def __init__(self, parent): self._parent=parent #this
I have this object: class a { public string Application; public DateTime From, To;
I have this simple structure: 1 parent, and two different childs. public class Parent{}
I have this code structure: public abstract class ContentEntryBase { public string UniqueIdentifier; public
I have the following Object: public class Constraint { @Id @GeneratedValue(strategy=GenerationType.IDENTITY) int id; String
Have the following structure [Serializable] public class Parent { public int x = 5;
I have a data.table object like this one library(data.table) a <- structure(list(PERMNO = c(10006L,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.