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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:43:04+00:00 2026-05-28T06:43:04+00:00

This time, my question is as simple as it sounds… how do you get

  • 0

This time, my question is as simple as it sounds… how do you get text to wrap in a WPF TreeViewItem?

I have a simple HierarchicalDataTemplate with just one TextBlock in it.

<TextBlock Text="{Binding Value}" TextWrapping="Wrap" />

The text does not wrap.

I tried binding the Width of the TextBlock to the ActualWidth of the TreeView, but although that makes the text wrap, the Width of the TreeViewItem does not fit in the TreeView because the TreeView has Padding. Binding to the ActualWidth of the TreeViewItem has (unsurprisingly) the same effect. Another downside to this is that even the items with little text stretch outside the TreeView bounds.

<TextBlock Text="{Binding Value}" TextWrapping="Wrap" Width="{Binding ActualWidth, 
ElementName=TreeView}" />

Surely there must be a better way, like somehow informing the TreeViewItem of the TreeView‘s bounds… I can’t believe it doesn’t know automatically. But how can I do this?

UPDATE >>>

Thanks to H.B.’s answer, I managed to change the Grid.ColumnSpan to 2 on the Bd Border he mentioned in the ControlTemplate and it set the width so that the text now wraps nicely. The problem is that I am using this ControlTemplate for other TreeViewItems in other TreeViews where I don’t want full width items.

The solution I came up with is simple. I have bound the TreeViewItem.Tag value to the Grid.ColumnSpan property in the ControlTemplate like so:

<Border Grid.ColumnSpan="{Binding Tag, RelativeSource={RelativeSource TemplatedParent}}" 
Name="Bd" Grid.Column="1" ... />

This allows me to change the Grid.ColumnSpan and therefore the full width or ordinary width behaviour of the TreeViewItem by setting the TreeViewItem.Tag value to either 2 or 1 respectively.

  • 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-28T06:43:05+00:00Added an answer on May 28, 2026 at 6:43 am

    If you look at the default template of TreeViewItems you will see a Grid like this:

    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition MinWidth="19"
                              Width="Auto"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <!-- ... -->
    

    As you can see the third column takes all available space while the others are on Auto, the header is placed in the second column inside a border:

    <Border Name="Bd"
            Grid.Column="1"
            ...
    

    This means that the column will become as large as the header, there is no restriction on it. Thus the header just gets bigger than the TreeView itself.

    If you add Grid.ColumnSpan="2" to this Border it will occupy the third column as well, which is restricted by how much space is left, hence the text will wrap; this will however extend the header across the whole width which might look a bit odd when selecting it.

    Of course you will also need to disable horizontal scrolling:

    <TreeView ScrollViewer.HorizontalScrollBarVisibility="Disabled" ...
    

    A screenshot

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

Sidebar

Related Questions

This is probably a very simple question, but at this time I have myself
Pretty simple question this time around. I have an application that communicates with another
I have a little question very simple this time I think... How Have I
I'm re-asking this question but with a different framework this time. I have two
This is a question I have wondered about for quite some time, yet I
Okay, Now admittedly this sounds like a silly question; But, I actually have a
This is going to be a very simple question, I have code that looks
This sounds like a simple question, but I don't know how to search for
Easy question this time. I'm trying to test whether or not a string does
A silly question, perhaps, but at this time of night, StackOverFlow is my only

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.