Windows Vista Forums
Vista Forums Home Join Vista Forums Webcasts Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > Avalon

Simplest way to right-align GridViewColumn

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 05-04-2006   #1 (permalink)
Sam Jost
Guest


 

Simplest way to right-align GridViewColumn

I've got a ListView, containing some numbers (currency and others), and
would like to be able to right-align the columns with numbers.

Since I can't find any tag on GridViewColumn to change the alignment,
whats the easiest way to achieve this?

Thanks,
Sam


My System SpecsSystem Spec
Old 05-04-2006   #2 (permalink)
Drew Marsh
Guest


 

Re: Simplest way to right-align GridViewColumn

Sam Jost wrote:

> I've got a ListView, containing some numbers (currency and others),
> and would like to be able to right-align the columns with numbers.
>
> Since I can't find any tag on GridViewColumn to change the alignment,
> whats the easiest way to achieve this?


I believe you'll need to define a CellTemplate for the column. In the template
just put a TextBlock and set it's TextAlignment to TextAlignment.Right. That
would look something like this:

<GridViewColumn ...>
<GridViewColumn.CellTempate>
<DataTemplate>
<TextBlock Text="{Binding Path=???}" TextAlignment="Right" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>

HTH,
Drew
___________________________________
Drew Marsh
Chief Software Architect
Mimeo.com, Inc. - http://www.mimeo.com
Microsoft C# / WPF MVP
Weblog - http://blog.hackedbrain.com/


My System SpecsSystem Spec
Old 05-05-2006   #3 (permalink)
Sam Jost
Guest


 

Re: Simplest way to right-align GridViewColumn

Drew,

I had to change it a bit to make it work, but it does the trick. In the
end for me it looks like:

<ListView.Resources>
<DataTemplate x:Key="MyTemplate">
<TextBlock HorizontalAlignment="Right" Block.TextAlignment="Right"
Text="{Binding Path=MyData}"/>
</DataTemplate>
</ListView.Resources>
[...]
<GridViewColumn Width="80" Header="my data"
CellTemplate="{StaticResource MyTemplate}"/>

Thanks for the hint!
Sam

Drew Marsh schrieb:

> Sam Jost wrote:
>
> > I've got a ListView, containing some numbers (currency and others),
> > and would like to be able to right-align the columns with numbers.
> >
> > Since I can't find any tag on GridViewColumn to change the alignment,
> > whats the easiest way to achieve this?

>
> I believe you'll need to define a CellTemplate for the column. In the template
> just put a TextBlock and set it's TextAlignment to TextAlignment.Right. That
> would look something like this:
>
> <GridViewColumn ...>
> <GridViewColumn.CellTempate>
> <DataTemplate>
> <TextBlock Text="{Binding Path=???}" TextAlignment="Right" />
> </DataTemplate>
> </GridViewColumn.CellTemplate>
> </GridViewColumn>
>
> HTH,
> Drew
> ___________________________________
> Drew Marsh
> Chief Software Architect
> Mimeo.com, Inc. - http://www.mimeo.com
> Microsoft C# / WPF MVP
> Weblog - http://blog.hackedbrain.com/


My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Align Desktop items in VISTA??? vamshi Vista General 4 07-17-2008 09:12 AM
Simplest (Vista-compatible) macro-maker ??? Vengeful Vista General 0 12-09-2007 12:31 PM
auto align icons horizontally Jeremy Schubert Vista General 0 07-08-2007 03:36 PM
How to right align text in a listview ? Pon Avalon 2 04-14-2007 02:13 PM
appyling styles to a GridViewColumn Jason Dolinger Avalon 15 02-21-2006 01:36 PM


Vistax64.com 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 2005-2008

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 47 48 49 50 51