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

The Archive Base Latest Questions

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

In learning WPF, I (perhaps unwisely) chose to display my XML data (wisely parsed

  • 0

In learning WPF, I (perhaps unwisely) chose to display my XML data (wisely parsed with LINQ) in a TreeView. But when I load it into a TreeView, it looks like this:

alt text

The XAML is as follows:

<TreeView Name="StoryTree">
    <TreeViewItem Name="TreeGeneral" Header="General"/>
    <TreeViewItem Name="TreeCharacters" Header="Characters" />
    <TreeViewItem Name="TreeEvents" Header="Events" />
    <TreeViewItem Name="TreeFactions" Header="Factions" />
    <TreeViewItem Name="TreeLocations" Header="Locations" />
    <TreeViewItem Name="TreePlots" Header="Plots" />
    <TreeViewItem Name="TreeReferences" Header="References" />
    <TreeViewItem Name="TreeScenes" Header="Scenes" />
</TreeView>

In the code-behind, I load the items into the treeview with a simple routine as follows:

    private void Update(StoryItem[] items, TreeViewItem parentNode)
    {
        //  Suppress updating if there are no actual changes.
        if (Changed(items, parentNode))
        {

            //  Remove all items from the child node.
            ClearItem(parentNode);

            //  Reinsert the child nodes.
            foreach (var item in items)
            {
                //  Create a TreeViewItem and insert it into the TreeView.
                //  Note that the item must support double clicking so that the 
                //  user can open the item. Also, we want to support tooltips
                //  for the items so that the summary text (if any) will display
                //  when the user hovers over the item with the mouse.
                TreeViewItem treeItem = new TreeViewItem();
                TextBlock block = new TextBlock();
                block.Text = item.Name;
                block.ToolTip = item.Summary;
                block.TextTrimming = TextTrimming.WordEllipsis;
                treeItem.Items.Add(block);
                parentNode.Items.Add(treeItem);
            }
        }
    }

I kind of suspect that this is the “cascading style inheritance” in WPF, but I’m not entirely sure (the top-level nodes look fine), but it might be something about the way I’m creating the child nodes.

DISCLAIMER:
Please don’t delve into talks about binding the treeview. For this particular app, the data is NEVER going to consist of more than a category header (top-level nodes) and the items immediately below them. What I want to know is why the top level nodes look fine and the ones I created are different from them.

I’ve tried eliminating the padding on both the TreeViewItem and the margin & padding on the TextBlock, both to no avail.

(Visual STudio 2008 SP1, .NET 3.5, Win7)

  • 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-17T20:16:19+00:00Added an answer on May 17, 2026 at 8:16 pm

    I think this is because you are adding your children inside another (redundant) tree item. As that tree item only contains a single child and no header, you are getting the extra level in the tree that you need to expand.

    Try the following:

            foreach (var item in items)
            {
                //  Create a TreeViewItem and insert it into the TreeView.
                //  Note that the item must support double clicking so that the 
                //  user can open the item. Also, we want to support tooltips
                //  for the items so that the summary text (if any) will display
                //  when the user hovers over the item with the mouse.
    
                TreeViewItem child = new TreeViewItem();
                child.Header = item.Name;
                child.ToolTip = item.Summary;
    
                parentNode.Items.Add(block);
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As I'm learning WPF I came across quite a few examples, but mostly all
For Quick learning WPF,I am following few books of WPF.But I don't know how
Learning WPF nowadays. Found something new today with .Net dependency properties. What they bring
I am learning WPF and was wondering if there is a way to show
I'm in the process of learning WPF coming from WinForms development. I have a
I've been using Winforms since .NET 1.1 and I want to start learning WPF.
I am learning Silverlight and WPF on my own to expand my programming base.
I'm working on a simple application to start learning my way around WPF. I
Just learning WPF databinding and have a gap in my understanding. I've seen a
So I am learning WPF right now, and want to do a simple databind

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.