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

  • SEARCH
  • Home
  • 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 1807984
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T06:12:18+00:00 2026-05-17T06:12:18+00:00

This problem has been solved before, but I’m just not getting it with examples

  • 0

This problem has been solved before, but I’m just not getting it with examples I’m finding online.

I have a class, lets say ‘ClassA’, this class has 2 string properties, ‘Property1’ and ‘Property2’ as well as an IEnumerable where ‘ClassB’ also has 2 properties. The list of ClassB will all be displayed in a nested treeview

I want these displayed in a treeview like so:

-ClassA[0]
  ClassA.Property1
  ClassA.Property2
  -ClassA.ClassB Title
   ClassB[0]
   ClassB[1]
   Etc.
+ClassA[1]
+ClassB[2]

It is my understanding that the way to accomplish this is to use HierarchicalDataTemplates however all examples I can find only tell me how to do:

-ClassA[0]
  -ClassA.ClassB Title
   ClassB[0]
   ClassB[1]
   Etc.
+ClassA[1]
+ClassB[2]

I cant figure out how to get the properties of ClassA in the template. Im thinking it’d be a DataTemplate on type ClassA but something isnt clicking.

Any help is greatly appreciated.

Thanks!

  • 1 1 Answer
  • 1 View
  • 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-05-17T06:12:19+00:00Added an answer on May 17, 2026 at 6:12 am

    Well, I answered my own question, but I dont think it’s the right way to go about this.

    I used an itemtemplate on the treeview and then created another treeview inside of that template with another itemtemplate on it.

    I can however, understand this when I look at it vs looking at the HierarchicalDataTemplates.

    WPF:

        <TreeView HorizontalAlignment="Left" Name="treeView1" VerticalAlignment="Top">
            <TreeView.ItemTemplate>
                <DataTemplate>
                    <TreeViewItem Header="{Binding FileName}">
                        <TextBlock Text="{Binding MetaData1}"/>
                        <TextBlock Text="{Binding MetaData2}"/>
                        <TreeViewItem ItemsSource="{Binding Mappings}" Header="Mappings">
                            <TreeViewItem.ItemTemplate>
                                <DataTemplate>
                                    <Grid>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="*"/>
                                            <ColumnDefinition Width="17"/>
                                            <ColumnDefinition Width="*"/>
                                        </Grid.ColumnDefinitions>
                                        <TextBlock Text="{Binding Original}" Grid.Column="0"/>
                                        <TextBlock Text="->" Grid.Column="1" Margin="3,0,3,0"/>
                                        <TextBlock Text="{Binding Mapping}" Grid.Column="2"/>
                                    </Grid>
                                </DataTemplate>
                            </TreeViewItem.ItemTemplate>
                        </TreeViewItem>
                    </TreeViewItem>
                </DataTemplate>
            </TreeView.ItemTemplate>
        </TreeView>
    

    Classes:

    public class ClassA
    {
        public string MetaData1 { get; set; }
        public string MetaData2 { get; set; }
        public string FileName { get; set; }
        public List<ClassB> Mappings { get; set; }
    }
    
    public class ClassB
    {
        public string Original { get; set; }
        public string Mapping { get; set; }
    }
    

    Quick Implementation of my data structure:

    new List<ClassA>
                        {
                            new ClassA
                                {
                                    FileName = "ClassA 1",
                                    MetaData1 = "Prop 1",
                                    MetaData2 = "Prop 2",
                                    Mappings = new List<ClassB>
                                                {
                                                    new ClassB
                                                    {
                                                        Original = "BProp 1",
                                                        Mapping = "BProp 2"
                                                    }
                                                }
                                },
                            new ClassA
                                {
                                    FileName = "ClassA 2",
                                    MetaData1 = "Prop 1",
                                    MetaData2 = "Prop 2",
                                    Mappings = new List<ClassB>
                                                {
                                                    new ClassB
                                                    {
                                                        Original = "BProp 1",
                                                        Mapping = "BProp 2"
                                                    }
                                                }
                                }
                        };
    

    If anyone knows how I should have done this better (with HierachicalDataTemplates and DataTemplates Im open to seeing that code and improving upon this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This problem has been solved before, but I'm just not getting it with examples
This problem must have been solved a million times, but Google has not been
Update II Problem Solved but Why? This has been the biggest headache ever. My
I have run into this problem before but never quite solved it. I have
This problem has been solved! Thanks a lot to Brad, Denis and junkie! You're
EDIT: This problem has been solved. See below. Hey all. I'm building an iPhone
i have an almost simular problem as posted before. My first problem has been
I know that this has been asked a million times before, but nothing that
for sure this question has been asked before, but I couldn't find any thread
This probably has been asked many times before but I was wondering how to

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.