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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:29:05+00:00 2026-05-21T02:29:05+00:00

In the following XAML, I am trying to wrap the TextBlock which binds to

  • 0

In the following XAML, I am trying to wrap the TextBlock which binds to “PortfolioCodes” and “CommentaryText” but it seems that “Wrapping” doesn’t work for TextBlock. I tried every possible suggestion I could find on this web site but all in vain. Can someone please help.

    <Grid>
    <ListBox ItemsSource="{Binding Path=Summaries}" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <Border CornerRadius="5" BorderBrush="LightGray" BorderThickness="1" Padding="4" Margin="4">
                    <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"></ColumnDefinition>
                            <ColumnDefinition Width="15"></ColumnDefinition>
                            <ColumnDefinition Width="Auto"></ColumnDefinition>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*"></RowDefinition>
                            <RowDefinition Height="*"></RowDefinition>
                            <RowDefinition Height="*"></RowDefinition>
                            </Grid.RowDefinitions>
                        <TextBlock Grid.Column="0" Grid.Row="0">No Of Security</TextBlock>
                        <TextBlock Grid.Column="2" Grid.Row="0" Text="{Binding Path=PortfolioSecurityCount}"></TextBlock>

                        <TextBlock Grid.Column="0" Grid.Row="1">Portfolio Code(s)</TextBlock>
                        <Grid Grid.Column="2" Grid.Row="1" >
                            <TextBlock TextWrapping="Wrap" Text="{Binding Path=PortfolioCodes}"></TextBlock>
                        </Grid>

                        <TextBlock Grid.Column="0" Grid.Row="2">Commentary Text</TextBlock>
                        <Grid Grid.Column="2" Grid.Row="2" >
                            <TextBlock Grid.Column="2" Grid.Row="2" TextWrapping="Wrap"  Text="{Binding Path=CommentaryText}"></TextBlock>
                        </Grid>
                    </Grid>
                </Border>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
</Grid>

Based on Guge response, I have changed xaml as below and now its working.

    <Grid x:Name="LayoutRoot">
    <ListBox x:Name="SummaryListBox" ItemsSource="{Binding Path=Summaries}" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <Border CornerRadius="5" BorderBrush="LightGray" BorderThickness="1" Padding="4" Margin="4">
                    <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"></ColumnDefinition>
                            <ColumnDefinition Width="15"></ColumnDefinition>
                            <ColumnDefinition Width="*"></ColumnDefinition>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*"></RowDefinition>
                            <RowDefinition Height="*"></RowDefinition>
                            <RowDefinition Height="*"></RowDefinition>
                            </Grid.RowDefinitions>
                        <TextBlock Grid.Column="0" Grid.Row="0">No Of Security</TextBlock>
                        <TextBlock Grid.Column="2" Grid.Row="0" Text="{Binding Path=PortfolioSecurityCount}"></TextBlock>

                        <TextBlock Grid.Column="0" Grid.Row="1">Portfolio Code(s)</TextBlock>
                        <TextBlock Grid.Column="2" Grid.Row="1" TextWrapping="Wrap" Text="{Binding Path=PortfolioCodes}" ></TextBlock>

                        <TextBlock Grid.Column="0" Grid.Row="2">Commentary Text</TextBlock>
                        <TextBlock Grid.Column="2" Grid.Row="2" TextWrapping="Wrap"  Text="{Binding Path=CommentaryText}"></TextBlock>
                    </Grid>
                </Border>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
</Grid>
  • 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-21T02:29:06+00:00Added an answer on May 21, 2026 at 2:29 am

    Change the width of your third ColumnDefinition from “Auto” to “*”, that way it only takes up whatever is left of your horizontal space.

    To try to explain this:
    Screen area in WPF is distributed in a two pass algorithm. First each visual element asks each child how much space it needs, with an indication of how much is available. These children do the same for their children.
    Then each visual element tells each child how much they are actually going to get. These children, again, do the same for their children.

    Your code failed to do what you wanted because the Grid in the DataTemplate told its third column children they could have all the horizontal space they wanted (“auto”) in the first run. Those textboxes then thought that they wouldn’t have to wrap. So they just reported back their desired width, and one line worth of height.
    In the second run the Grid found that “auto” turned out to be a little less than what those children wanted. And the Grid still only gave them one line worth of height, so wrapping was out of the question. The children then had no other option left to them but to truncate the text.

    When the third column width is set to “*”, the grid will tell the children in the that column exactly how many horizontal pixels are left after the first column got their “auto” and the second column got their 15. Now the textboxes can figure out that they may want to wrap, and they report back “Ok, Dad, I’ll make do with those measly horizontal pixels, but at least give me what I want in verticals”. There is no limit to the vertical space, so they get what they need to present all their glorious content.

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

Sidebar

Related Questions

I have following XAML: <TextBlock HorizontalAlignment=Center VerticalAlignment=Center FontSize=10 FontFamily=Arial Foreground=#414141> <Run Text={Binding LoadsCount} />
I have the following XAML, that does all that it is supposed to, except
I have the following XAML (simple list box with custom DataTemplate). I'm trying to
Considering the following sample XAML file, which shows the first 1000 people of Facebook,
In the following XAML, I am trying to bind the various DataTemplates directly to
I'm trying to display a string in XAML using Label control. Following is my
I have the following xaml and I am trying to get to the Grid
I have the following Xaml in a Window ( ArtistInfo ): <Grid> <TextBlock Text={Binding
I'm trying to assign some SystemColor foreground to a TextBlock on XAML for WPF.
The following xaml code works: <Window x:Class=DerivedTemplateBug.Window1 xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:local=clr-namespace:DerivedTemplateBug Title=Window1 Height=300 Width=300> <Button>

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.