Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - Problem with alignment of text in a listview

 
 
Old 10-02-2007   #1 (permalink)
keithabarker


 
 

Problem with alignment of text in a listview

I am having problems getting a listview with a gridview to align the text
within a cell.

I downloaded the SDK sample "ListView That Uses a GridView with Templates
Sample" from http://msdn2.microsoft.com/en-us/library/ms771780.aspx

This includes a cell template that uses:

<DataTemplate x:Key="myCellTemplateYear">
<DockPanel>
<TextBlock Foreground="DarkBlue" HorizontalAlignment="Center">
<TextBlock.Text>
<Binding Path="Year"/>
</TextBlock.Text>
</TextBlock>
</DockPanel>
</DataTemplate>

I would expect this to align the "Year" in the "Center" of each cell.
But this does not happen - it is always "Left" aligned.

Is this a bug in WPF or in the SDK sample?

Any hints on how to modify the sample to Right justify the Year would be
greatly appreciated.

Thanx


My System SpecsSystem Spec
Old 10-24-2007   #2 (permalink)
Dayne Bratsman


 
 

RE: Problem with alignment of text in a listview

The ListViewItems that contain your cells default to Left content alignment.
You can override that with this:

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

"keithabarker" wrote:
Quote:

> I am having problems getting a listview with a gridview to align the text
> within a cell.
>
> I downloaded the SDK sample "ListView That Uses a GridView with Templates
> Sample" from http://msdn2.microsoft.com/en-us/library/ms771780.aspx
>
> This includes a cell template that uses:
>
> <DataTemplate x:Key="myCellTemplateYear">
> <DockPanel>
> <TextBlock Foreground="DarkBlue" HorizontalAlignment="Center">
> <TextBlock.Text>
> <Binding Path="Year"/>
> </TextBlock.Text>
> </TextBlock>
> </DockPanel>
> </DataTemplate>
>
> I would expect this to align the "Year" in the "Center" of each cell.
> But this does not happen - it is always "Left" aligned.
>
> Is this a bug in WPF or in the SDK sample?
>
> Any hints on how to modify the sample to Right justify the Year would be
> greatly appreciated.
>
> Thanx
>
My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
Desktop icon text -alignment? General Discussion
WPF ListView focus problem. .NET General
HP PSC 2101 alignment problem Vista print fax & scan


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46