Switch Parent Children relationship in C#

Using C# and WPF I have a situation where my data is organized hierarchically.
I am using a treeview to represent this :

  • Group_01
    • Object_01
      • Material_01
        • Texture
      • Material_02
        • Texture_02
  • Group_02
    • Object_02
      • Material_03
        • Texture_03

I would like to be able to switch the order of the hierarchy, for example be able to create the data starting from the Materials and know all the objects that use that particular material

  • Material_02
    • Object_01
      • Group_01
    • Object_02
      • Group_02

What is it the recommended data structure to organize the data? And how I could switch easily between any of these visualizations?

5

To be able to do this, you will need to modify your data type classes so that the Material class has a collection of type Object and your Object class (which is a really bad name if this is a custom class) should have a collection of type Group. The Object class will also need a collection of type Material and the Material class will also need a collection of type Texture, etc.

Then you would need to design a function (with loads of Linq or loops) that reverses the hierarchy. The easiest way to do this is if you add properties into your data type classes that relate to each other. Therefore, they should all have some kind of Id property and then the relevant child classes would need to have ParentId properties.

With this setup, you can easily build your hierarchies:

Material material = new Material();
material.Id = theIdValue;
material.Textures = new ObservableCollection(allTextTures.Where(t => t.ParentId == 
material.Id).ToList());

1

Since here you have many to many relationships i.e group can have object list which inturn can have material list and the list of groups it belongs to… similarly material can have object list.. so your models should be like below:

    public class Group
    {
        ObservableCollection<Object> Objects { get; set; }
    }

    public class Object
    {
        ObservableCollection<Material> Materials { get; set; }
        ObservableCollection<Group> Groups { get; set; }
    }

    public class Material
    {
        ObservableCollection<Object> Objects { get; set; }
    }

Now in order to show the hierarchical data you can use the TreeView to represent this and can define the HierarchicalDataTemplates depending on your number of visualization e.g for GroupHierarchy and MateraialHierarchy you can have templates like:

Group Hierarchy:

<HierarchicalDataTemplate x:Key="GroupTemplate" ItemsSource="{Binding Objects}">
            <StackPanel>
                <TextBlock Text="{Binding GroupName}"/>
            </StackPanel>
            <HierarchicalDataTemplate.ItemTemplate>
                <HierarchicalDataTemplate ItemsSource="{Binding Materials}">
                    <TextBlock Text="{Binding ObjectName}"/>
                    <HierarchicalDataTemplate.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding MaterialName}"/>
                        </DataTemplate>
                    </HierarchicalDataTemplate.ItemTemplate>
                </HierarchicalDataTemplate>
            </HierarchicalDataTemplate.ItemTemplate>
        </HierarchicalDataTemplate>

Material hierarchy:

<HierarchicalDataTemplate x:Key="MaterialTemplate" ItemsSource="{Binding Objects}">
            <StackPanel>
                <TextBlock Text="{Binding MaterialName}"/>
            </StackPanel>
            <HierarchicalDataTemplate.ItemTemplate>
                <HierarchicalDataTemplate ItemsSource="{Binding Groups}">
                    <TextBlock Text="{Binding ObjectName}"/>
                    <HierarchicalDataTemplate.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding GroupName}"/>
                        </DataTemplate>
                    </HierarchicalDataTemplate.ItemTemplate>
                </HierarchicalDataTemplate>
            </HierarchicalDataTemplate.ItemTemplate>
        </HierarchicalDataTemplate>

Now you can use ItemTemplateSelector to return the correct template for your TreeView when you switch the TreeView’s ItemsSource

1

I would focus on what each object is without focussing on how it will be displayed. What is a node? Looking at your treeview, it looks like a node is an item with various properties – would a filtering system based on numerous categories perhaps work better than a treeview?

Then a user could say I want “material x” with “texture y” but only in “group b” without needing to navigate through a hierachy?

It’s hard to give you concrete advice without knowing what a node actually represents. Also, might be worth looking at ux.stackexchange.com for front end visualisation ideas.

3

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

Switch Parent Children relationship in C#

Using C# and WPF I have a situation where my data is organized hierarchically.
I am using a treeview to represent this :

  • Group_01
    • Object_01
      • Material_01
        • Texture
      • Material_02
        • Texture_02
  • Group_02
    • Object_02
      • Material_03
        • Texture_03

I would like to be able to switch the order of the hierarchy, for example be able to create the data starting from the Materials and know all the objects that use that particular material

  • Material_02
    • Object_01
      • Group_01
    • Object_02
      • Group_02

What is it the recommended data structure to organize the data? And how I could switch easily between any of these visualizations?

5

To be able to do this, you will need to modify your data type classes so that the Material class has a collection of type Object and your Object class (which is a really bad name if this is a custom class) should have a collection of type Group. The Object class will also need a collection of type Material and the Material class will also need a collection of type Texture, etc.

Then you would need to design a function (with loads of Linq or loops) that reverses the hierarchy. The easiest way to do this is if you add properties into your data type classes that relate to each other. Therefore, they should all have some kind of Id property and then the relevant child classes would need to have ParentId properties.

With this setup, you can easily build your hierarchies:

Material material = new Material();
material.Id = theIdValue;
material.Textures = new ObservableCollection(allTextTures.Where(t => t.ParentId == 
material.Id).ToList());

1

Since here you have many to many relationships i.e group can have object list which inturn can have material list and the list of groups it belongs to… similarly material can have object list.. so your models should be like below:

    public class Group
    {
        ObservableCollection<Object> Objects { get; set; }
    }

    public class Object
    {
        ObservableCollection<Material> Materials { get; set; }
        ObservableCollection<Group> Groups { get; set; }
    }

    public class Material
    {
        ObservableCollection<Object> Objects { get; set; }
    }

Now in order to show the hierarchical data you can use the TreeView to represent this and can define the HierarchicalDataTemplates depending on your number of visualization e.g for GroupHierarchy and MateraialHierarchy you can have templates like:

Group Hierarchy:

<HierarchicalDataTemplate x:Key="GroupTemplate" ItemsSource="{Binding Objects}">
            <StackPanel>
                <TextBlock Text="{Binding GroupName}"/>
            </StackPanel>
            <HierarchicalDataTemplate.ItemTemplate>
                <HierarchicalDataTemplate ItemsSource="{Binding Materials}">
                    <TextBlock Text="{Binding ObjectName}"/>
                    <HierarchicalDataTemplate.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding MaterialName}"/>
                        </DataTemplate>
                    </HierarchicalDataTemplate.ItemTemplate>
                </HierarchicalDataTemplate>
            </HierarchicalDataTemplate.ItemTemplate>
        </HierarchicalDataTemplate>

Material hierarchy:

<HierarchicalDataTemplate x:Key="MaterialTemplate" ItemsSource="{Binding Objects}">
            <StackPanel>
                <TextBlock Text="{Binding MaterialName}"/>
            </StackPanel>
            <HierarchicalDataTemplate.ItemTemplate>
                <HierarchicalDataTemplate ItemsSource="{Binding Groups}">
                    <TextBlock Text="{Binding ObjectName}"/>
                    <HierarchicalDataTemplate.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding GroupName}"/>
                        </DataTemplate>
                    </HierarchicalDataTemplate.ItemTemplate>
                </HierarchicalDataTemplate>
            </HierarchicalDataTemplate.ItemTemplate>
        </HierarchicalDataTemplate>

Now you can use ItemTemplateSelector to return the correct template for your TreeView when you switch the TreeView’s ItemsSource

1

I would focus on what each object is without focussing on how it will be displayed. What is a node? Looking at your treeview, it looks like a node is an item with various properties – would a filtering system based on numerous categories perhaps work better than a treeview?

Then a user could say I want “material x” with “texture y” but only in “group b” without needing to navigate through a hierachy?

It’s hard to give you concrete advice without knowing what a node actually represents. Also, might be worth looking at ux.stackexchange.com for front end visualisation ideas.

3

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

Switch Parent Children relationship in C#

Using C# and WPF I have a situation where my data is organized hierarchically.
I am using a treeview to represent this :

  • Group_01
    • Object_01
      • Material_01
        • Texture
      • Material_02
        • Texture_02
  • Group_02
    • Object_02
      • Material_03
        • Texture_03

I would like to be able to switch the order of the hierarchy, for example be able to create the data starting from the Materials and know all the objects that use that particular material

  • Material_02
    • Object_01
      • Group_01
    • Object_02
      • Group_02

What is it the recommended data structure to organize the data? And how I could switch easily between any of these visualizations?

5

To be able to do this, you will need to modify your data type classes so that the Material class has a collection of type Object and your Object class (which is a really bad name if this is a custom class) should have a collection of type Group. The Object class will also need a collection of type Material and the Material class will also need a collection of type Texture, etc.

Then you would need to design a function (with loads of Linq or loops) that reverses the hierarchy. The easiest way to do this is if you add properties into your data type classes that relate to each other. Therefore, they should all have some kind of Id property and then the relevant child classes would need to have ParentId properties.

With this setup, you can easily build your hierarchies:

Material material = new Material();
material.Id = theIdValue;
material.Textures = new ObservableCollection(allTextTures.Where(t => t.ParentId == 
material.Id).ToList());

1

Since here you have many to many relationships i.e group can have object list which inturn can have material list and the list of groups it belongs to… similarly material can have object list.. so your models should be like below:

    public class Group
    {
        ObservableCollection<Object> Objects { get; set; }
    }

    public class Object
    {
        ObservableCollection<Material> Materials { get; set; }
        ObservableCollection<Group> Groups { get; set; }
    }

    public class Material
    {
        ObservableCollection<Object> Objects { get; set; }
    }

Now in order to show the hierarchical data you can use the TreeView to represent this and can define the HierarchicalDataTemplates depending on your number of visualization e.g for GroupHierarchy and MateraialHierarchy you can have templates like:

Group Hierarchy:

<HierarchicalDataTemplate x:Key="GroupTemplate" ItemsSource="{Binding Objects}">
            <StackPanel>
                <TextBlock Text="{Binding GroupName}"/>
            </StackPanel>
            <HierarchicalDataTemplate.ItemTemplate>
                <HierarchicalDataTemplate ItemsSource="{Binding Materials}">
                    <TextBlock Text="{Binding ObjectName}"/>
                    <HierarchicalDataTemplate.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding MaterialName}"/>
                        </DataTemplate>
                    </HierarchicalDataTemplate.ItemTemplate>
                </HierarchicalDataTemplate>
            </HierarchicalDataTemplate.ItemTemplate>
        </HierarchicalDataTemplate>

Material hierarchy:

<HierarchicalDataTemplate x:Key="MaterialTemplate" ItemsSource="{Binding Objects}">
            <StackPanel>
                <TextBlock Text="{Binding MaterialName}"/>
            </StackPanel>
            <HierarchicalDataTemplate.ItemTemplate>
                <HierarchicalDataTemplate ItemsSource="{Binding Groups}">
                    <TextBlock Text="{Binding ObjectName}"/>
                    <HierarchicalDataTemplate.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding GroupName}"/>
                        </DataTemplate>
                    </HierarchicalDataTemplate.ItemTemplate>
                </HierarchicalDataTemplate>
            </HierarchicalDataTemplate.ItemTemplate>
        </HierarchicalDataTemplate>

Now you can use ItemTemplateSelector to return the correct template for your TreeView when you switch the TreeView’s ItemsSource

1

I would focus on what each object is without focussing on how it will be displayed. What is a node? Looking at your treeview, it looks like a node is an item with various properties – would a filtering system based on numerous categories perhaps work better than a treeview?

Then a user could say I want “material x” with “texture y” but only in “group b” without needing to navigate through a hierachy?

It’s hard to give you concrete advice without knowing what a node actually represents. Also, might be worth looking at ux.stackexchange.com for front end visualisation ideas.

3

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật