DataGrid Column HorizontalAlignment Right ?

Please post public support tickets here. Note: for private support tickets, please send an email to support@cshtml5.com instead.
Sesztak
Posts: 172
Joined: Fri Jun 24, 2016 2:19 am

DataGrid Column HorizontalAlignment Right ?

Postby Sesztak » Thu Jul 28, 2016 4:25 am

Dear JS-Support,

Is there any way to change the horizontal alignment from Left to Right of certain column of Datagrid ?

(Background: we have a lot of numbers -amounts- in a DataGridTextColumn: we used to align it to right to get the same decimal places are below each other)

The pseudo code In WPF :

<DataGridTextColumn Header="Amount" Binding="{Binding Amount}">
<DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="HorizontalAlignment" Value="Right" />
</Style>
</DataGridTextColumn.ElementStyle>

</DataGridTextColumn>

The problem: there is no <DataGridTextColumn.ElementStyle> in CSHTML5 current implementation.

Any advise/workaround?

Thanks in advance,
Best Regards,
Péter

JS-Support @Userware
Site Admin
Posts: 1142
Joined: Tue Apr 08, 2014 3:42 pm

Re: DataGrid Column HorizontalAlignment Right ?

Postby JS-Support @Userware » Thu Jul 28, 2016 8:24 am

We are going to look into this.

Sesztak
Posts: 172
Joined: Fri Jun 24, 2016 2:19 am

Re: DataGrid Column HorizontalAlignment Right ?

Postby Sesztak » Thu Jul 28, 2016 11:17 pm

in the meantime a solution by a workaround:

<DataGridTemplateColumn Header="Amount">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock HorizontalAlignment="Right" Text="{Binding Amount}" FontSize="18" FontWeight="Bold" Margin="6" Padding="6"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>

I hope it helps others.

The important part: you can do it by custom DataGridTemplateColumn : using DataTemplate you should set TextBlock HorizontalAlignment="Right".

best regards,
Péter

JS-Support @Userware
Site Admin
Posts: 1142
Joined: Tue Apr 08, 2014 3:42 pm

Re: DataGrid Column HorizontalAlignment Right ?

Postby JS-Support @Userware » Fri Jul 29, 2016 7:05 am

Thank you for the workaround.


Return to “Technical Support”

Who is online

Users browsing this forum: No registered users and 43 guests