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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T04:42:43+00:00 2026-05-21T04:42:43+00:00

I did some googling on the this found several references which did similar things

  • 0

I did some googling on the this found several references which did similar things to the example below. When I try this, the first column is aligned right initialy.
Without the setter for HorizontalContentAlignment the text stays put when the column is resized instead of tracking the right edge of the column. Adding the setter has the effect of centring the TextBlock in the column as it is resized but it does not stretch to fit the column. I changed the background colour of the first column to hightlight what is happening. I am using VS 2008 with version 3.5 SP1 of the framework.

<Window.Resources>
    <XmlDataProvider x:Key="CharacterData">
        <x:XData>
            <Data xmlns="">
                <Character First="Bart" Last="Simpson" />
                <Character First="Homer" Last="Simpson" />
                <Character First="Lisa" Last="Simpson" />
                <Character First="Maggie" Last="Simpson" />
                <Character First="Marge" Last="Simpson" />
            </Data>
        </x:XData>
    </XmlDataProvider>
</Window.Resources>

<ListView ItemsSource="{Binding Source={StaticResource CharacterData},
  XPath=Data/Character}" >

    <ListView.ItemContainerStyle>
        <Style TargetType="ListViewItem">
            <Setter Property="HorizontalContentAlignment" Value="Stretch" />
        </Style>
    </ListView.ItemContainerStyle>

    <ListView.View>
        <GridView>
            <GridViewColumn Width="100" Header="First Name" >
                <GridViewColumn.CellTemplate >
                    <DataTemplate>
                        <TextBlock Width="98" Margin="-6,0" TextAlignment="Right" Text="{Binding XPath=@First}" Background="Aqua" HorizontalAlignment="Stretch" />
                    </DataTemplate>
                </GridViewColumn.CellTemplate>
            </GridViewColumn>
            <GridViewColumn Width="100" Header="Last Name">
                <GridViewColumn.CellTemplate>
                    <DataTemplate>
                        <TextBlock Width="100" Margin="-6,0" TextAlignment="Left" Text="{Binding XPath=@Last}" />
                    </DataTemplate>
                </GridViewColumn.CellTemplate>
            </GridViewColumn>
        </GridView>
    </ListView.View>
</ListView>

Update: Removing the width parameter from the TextBox allows the stretching defined in the ItemContainerStyle to work properly.

<DataTemplate>
   <TextBlock  Margin="-6,0" TextAlignment="Right" Text="{Binding XPath=@First}" Background="Aqua"  />
</DataTemplate>
  • 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-21T04:42:44+00:00Added an answer on May 21, 2026 at 4:42 am

    You need to put HorizontalContentAlignment="Stretch" onto your listview.

    Update: I meant the list view itself, not the container style:

    <ListView ItemsSource="{Binding Source={StaticResource CharacterData}, XPath=Data/Character}" HorizontalContentAlignment="Stretch">
    

    Update2: I just noticed that you have set the Width of your text blocks – that’s why they are not stretching. Remove the Width and replace it with MinWidth if you want a minimum width

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

Sidebar

Related Questions

Solution I did some googling and found this forum post , and here is
This is pasted from a website, which presumably was working. I did some googling
I did some googling to try to answer this question but even after that
Did some googling and couldn't find a clear answer on this. My assumption is
I did do some googling and searching on this site but did not find
I did some googling, and came to the script below, Can anyone help /me
How to install Ldap on windows7 and to configure it?? Did some googling..cant find
Did some searches here & on the 'net and haven't found a good answer
I did some research and found that the only way to vertically center a
I'm new to WordPress and just installed version 3.3.1. I did some googling regarding

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.