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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:48:05+00:00 2026-05-24T17:48:05+00:00

Its been a while since I’ve had to mess with the syntax to actually

  • 0

Its been a while since I’ve had to mess with the syntax to actually hook up an XML data set using XElement to a WPF TreeView. I’ve tried to recreate a pretty simple example, but I get nothing displaying in the TreeView.

Here is my XAML

<Window.Resources>
    <HierarchicalDataTemplate ItemsSource="{Binding Path=Elements}" x:Key="ViewEditTreeTemplate">
        <StackPanel Orientation="Horizontal" Margin="1">
            <Label x:Name="ElementHeaderLabel" Content="{Binding Path=Name.LocalName}" />
        </StackPanel>
    </HierarchicalDataTemplate>
</Window.Resources>


<Grid>
    <TreeView  Name="DataTree" ItemsSource="{Binding Source={StaticResource ViewEditTreeTemplate}}" Height="160"  Width="176" />
</Grid>

And here is the code behind.

XElement Element = XElement.Load("test.xml");
DataTree.DataContext = Element;

The “test.xml” is properly formatted and there are no errors while loading it. I don’t understand why nothing displays after I set the data context.

  • 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-24T17:48:06+00:00Added an answer on May 24, 2026 at 5:48 pm

    You did not set the ItemTemplate of the TreeView (you appear to have accidentally set it as ItemsSource) and you cannot implicitly apply templates to XML data making it a resource (further you set a Key which prevents that either way).

    I think in code behind you should set the ItemsSource instead of the DataContext, it should be either a list of root elements or a one-element-list containing the root element only.

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

Sidebar

Related Questions

Its been a while since I had to do some Java/JSP... I have a
It's been a while since I've had to do any HTML-like code in Vim
Its been a while since my Database Design classes in my sophomore year at
Its been a while since I've done any hard core web design, so I
Its been a while since i've needed to do this so i was looking
Ok, its been a while since I've done any file input or string manipulation
Trying to wrap this short example in C++. (and its been a while since
So this is a purely academic question, mostly as its been a while since
Its been a while since I worked in asp.net and a very long time
Okay its been a while since I used mod rewrite and I created a

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.