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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:58:42+00:00 2026-05-14T14:58:42+00:00

Lets say I have the following data: <XmlDataProvider x:Key=Values> <x:XData> <folder name=C:> <folder name=stuff

  • 0

Lets say I have the following data:

<XmlDataProvider x:Key="Values">
  <x:XData>
    <folder name="C:">
      <folder name="stuff" />
      <folder name="things" />
      <folder name="windows">
        <folder name="system32" />
      </folder>
    </folder>
  </x:XData>
</XmlDataProvider>

How can I get that into a treeview? I can’t seem to grok hierarchical binding…

I know that I can get it in there in C# code, but I wanted to do it with a binding expression.

  • 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-14T14:58:42+00:00Added an answer on May 14, 2026 at 2:58 pm

    EDIT: Didn’t see that you wanted to do this in XAML only. This MSDN post should help you out.

    HierarchicalDataTemplate isn’t so bad if your data is already in a hierarchical form. Let’s say you translate that XML data into a model class using code like this:

    public partial class TreeViewHierarchy : Window
    {
        public ObservableCollection<Folder> Folders
        {
            get;
            set;
        }
    
        public TreeViewHierarchy()
        {
            Folder system32 = new Folder() { Name = "system32" };
            Folder windows = new Folder() { Name = "windows", 
                Children = new ObservableCollection<Folder>() { system32 } };
    
            Folder things = new Folder() { Name = "things" };
            Folder stuff = new Folder() { Name = "stuff" };
    
            Folder c = new Folder() { Name = "C:",
                Children = new ObservableCollection<Folder>() { stuff, things, windows } };
    
            Folders = new ObservableCollection<Folder>() { c };
    
            InitializeComponent();
    
        }
    }
    
    public class Folder
    {
        public string Name
        {
            get;
            set;
        }
    
        public ObservableCollection<Folder> Children
        {
            get;
            set;
        }
    }
    

    Then the XAML for your TreeView would be as simple as this:

    <Window x:Class="TestWpfApplication.TreeViewHierarchy"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="TreeViewHierarchy" Height="300" Width="300"
    DataContext="{Binding RelativeSource={RelativeSource Self}}">
    <TreeView ItemsSource="{Binding Folders}">
        <TreeView.ItemTemplate>
            <HierarchicalDataTemplate ItemsSource="{Binding Children}">
                <TextBlock Text="{Binding Name}"/>
            </HierarchicalDataTemplate>
        </TreeView.ItemTemplate>
    </TreeView>
    

    And the result:

    alt text http://img191.imageshack.us/img191/7841/treeviewhierarchy.png

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

Sidebar

Related Questions

Lets say we have the following: create view view_1 as ( select key, data
lets say i have the following RGB values: R:129 G:98 B:87 Photoshop says the
Lets say I have the following mapping: <hibernate-mapping package=mypackage> <class name=User table=user> <id name=id
Lets say i have following class public class abc { int id; string name;
Lets say I have a table with some data like the following: ID text
I have the following mysql table called test. lets say it has the data
Lets say I have a text file with the following data Username User ID
Lets say I have the following class structure in my data access layer: interface
I have a file, lets say bigfile, with tabular data of the following form,
Let's say I have a table containing following data: | id | t0 |

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.