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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:38:11+00:00 2026-05-17T01:38:11+00:00

I am trying to get the header text of a TreeviewItem to be set

  • 0

I am trying to get the header text of a TreeviewItem to be set in the binding to an XML source. Everything is working fine except the only thing that appears in the header is the text I’m binding to and nothing else in the string format. Example:

<HierarchicalDataTemplate x:Key="LogDataTemp" ItemsSource="{Binding Path=log}">
    <TreeViewItem>
        <TreeViewItem.Header>
            <Binding Path="Attribute[level].Value" StringFormat="TEST \{0\}" />
        </TreeViewItem.Header>
    </TreeViewItem>
</HierarchicalDataTemplate>

In this case the level value appears but nothing else. I have tried dozens of different ways of approaching this and it seems that nothing works.

  • 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-17T01:38:12+00:00Added an answer on May 17, 2026 at 1:38 am

    Don’t escape the braces in the StringFormat. You want to apply the formatting to the 0th-element in your binding.

    For instance, with a simple property called “Level”:

            <TextBlock x:Name="txtUnformatted" Grid.Row="0" Foreground="White" >
                <TextBlock.Text>
                    <Binding Path="Level" />
                </TextBlock.Text>
            </TextBlock>
    
            <TextBlock x:Name="txtFormatted" Grid.Row="1" Foreground="White">
                <TextBlock.Text>
                    <Binding Path="Level" StringFormat="Test {0:000000}" />
                </TextBlock.Text>
            </TextBlock>
    

    And the result is something like:
    alt text

    Update

    Also, the default implementation of the Header, when you don’t add any controls, is a simple ContentPresenter, which doesn’t apply formatting. To work around this, simply put a TextBlock into the header, and bind the text you want formatted to that.

    <HierarchicalDataTemplate x:Key="LogDataTemp" ItemsSource="{Binding Path=log}">
        <TreeViewItem>
            <TreeViewItem.Header>
                <TextBlock>
                    <TextBlock.Text>
                         <Binding Path="Attribute[level].Value" 
                                  StringFormat="TEST {0}" />
                    </TextBlock.Text>
                </TextBlock>
            </TreeViewItem.Header>
        </TreeViewItem>
    </HierarchicalDataTemplate>
    

    It is perfectly acceptable (and commonly done) to put controls into a header control (for instance, a grid containing an image and a label). The beauty of WPF.

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

Sidebar

Related Questions

I'm trying to do : document.getElementById(header-text).innerHTML = something interesting; It's working fine with every
I'm trying to get a header aligned with a body of text by baseline,
Im trying to get something like this: <ul> <li> <h3>Some header</h3> <p>Some text</p> </li>
Hello I have a header that I am trying to get working and I
Trying to get the header to stick to the top of the page -
So I'm trying to get a navigation layout for a header like the one
Trying to build a legacy code in VS2005 and get errors in VC header
So i am trying get 2 div-containers which both should contain centered text (Both
Trying to get a wildcard search to pick up on any text in org_name
I'm trying to put row header text based on a converter function of the

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.