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 7668097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:16:19+00:00 2026-05-31T15:16:19+00:00

I am trying the absolute simplest use of HierarchicalDataTemplate to bind nested data to

  • 0

I am trying the absolute simplest use of HierarchicalDataTemplate to bind nested data to a WPF TreeView. For some reason, the children of my tree are not visible:

                                                enter image description here

Here is the entire XAML:

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:src="clr-namespace:WpfApplication1"
        Title="MainWindow" Height="350" Width="525">
    <TreeView Name="ctTree">
        <TreeView.Resources>
            <HierarchicalDataTemplate DataType = "{x:Type src:MyClass}"
                                      ItemsSource = "{Binding Path=Children}">
                <TextBlock Text="{Binding Path=Name}"/>
            </HierarchicalDataTemplate>
        </TreeView.Resources>
    </TreeView>
</Window>

and here’s all of C# behind this, apart from usings and the namespace:

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();

        var collection = new ObservableCollection<MyClass>
        {
            new MyClass { Name = "parent one" },
            new MyClass { Name = "parent two" },
        };
        collection[0].Children.Add(new MyClass { Name = "child one" });
        collection[0].Children.Add(new MyClass { Name = "child two" });
        ctTree.ItemsSource = collection;
    }
}

class MyClass
{
    public string Name { get; set; }
    public ObservableCollection<MyClass> Children
        = new ObservableCollection<MyClass>();
}

Note that the data template does actually apply to the items: the data is taken from the Name property, and if the template didn’t apply would show as “MyClass” instead.

How do I get the children to show? I seem to be doing exactly the same thing as all examples on HierarchicalDataTemplate.

  • 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-05-31T15:16:20+00:00Added an answer on May 31, 2026 at 3:16 pm

    MyClass.Children is a field, not a property. You cannot bind to a field, convert Children field to a property and everything should work then:

    class MyClass
    {
        public string Name { get; set; }
        public ObservableCollection<MyClass> Children { get; private set; }
    
        public MyClass()
        {
            Children = new ObservableCollection<MyClass>();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here are some models I am trying to load data for: class School(models.Model): name
Is absolute absolute or not? I am trying to make an input form with
I'm working with ASP.NET MVC3, and I'm trying to get absolute control over my
I am trying to decypher an absolute monstrosity of a stored procedure and i'm
I'm trying to convert ~/Uploads/Images/ to an absolute path I can create a FileStream
I am an absolute newbie in Haskell yet trying to understand how it works.
Trying to comply with StackOverflow's suggestion of asking a question, not creating a discussion,
Trying to use this method (gist of which is use self.method_name in the FunnyHelper
Trying to parse an HTML document and extract some elements (any links to text
Trying to determine if it is possible to bind the SelectedValue of a ComboBox

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.