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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:02:46+00:00 2026-05-23T21:02:46+00:00

I have an XML file I deserialized into an object, and now I want

  • 0

I have an XML file I deserialized into an object, and now I want to display that object in a WPF TreeView. I have been looking in to Data Bindings with the WPF TreeView but I have not been able to find what I am looking for.

Is there a way to have the WPF TreeView display an object and it’s children without knowing in advance what the object structure looks like?

  • 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-23T21:02:48+00:00Added an answer on May 23, 2026 at 9:02 pm

    Assuming your object looks something like:

        Entity A
            Entity B
                Entity C
                Entity C
            Entity B
        Entity D
    

    Create a hierarchical data template for each non leaf entity and a data template for each leaf entity.

    I’ve found it easy to accommodate any type of mixed hierarchy if you have in your objects an ObservableCollection (called something like Items) at each level that contains the children of any type below it.

    With this setup, the templates would look something like:

            <!-- entity a-->
            <HierarchicalDataTemplate DataType="{x:Type local:EntityA}" ItemsSource="{Binding Items, Mode=OneWay}">
                <StackPanel>
                  <!-- your content >
                </StackPanel>
            </HierarchicalDataTemplate>
            <!-- entity b -->
            <HierarchicalDataTemplate DataType="{x:Type local:EntityB}" ItemsSource="{Binding Items, Mode=OneWay}">
                <StackPanel>
                  <!-- your content >
                </StackPanel>
            </HierarchicalDataTemplate>
            <!-- entity c -->
            <DataTemplate DataType="{x:Type local:EntityC}">
                <StackPanel>
                  <!-- your content >
                </StackPanel>
            </DataTemplate>
            <!-- entity d -->
            <DataTemplate DataType="{x:Type local:EntityD}">
                <StackPanel>
                  <!-- your content >
                </StackPanel>
            </DataTemplate>
    

    And the tree view binding:

        <TreeView ItemsSource="{Binding Items, Mode=OneWay}" />
    

    This answer assumes you know the types of objects you are dealing with, but want to handle any structure/hierarchy of those objects, and if you don’t know if a particular object type is going to be a leaf one or not, you can always use hierarchical data templates.

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

Sidebar

Related Questions

I have an XML file that I deserialize into a class object. This class
I have an xml file providing data for a datagrid in Flex 2 that
I have an XML file and I want to retrieve data from it so
I have an XML file that has data in it, but one of the
I have an xml file stored on my website that looks like this: <games>
I have a XML file that I need to parse in the Android SDK.
I have an XML file in the drawable-folder. I want parse the XML-file using
I have an XML file that starts like this: <Elements name=Entities xmlns=XS-GenerationToolElements> I'll have
I have an xml file which i use for database, meaning that the xml
I have this xml snippet as part of a xml file that will be

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.