Page 1 of 1

DataGrid Column HorizontalAlignment Right ?

Posted: Thu Jul 28, 2016 4:25 am
by Sesztak
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

Re: DataGrid Column HorizontalAlignment Right ?

Posted: Thu Jul 28, 2016 8:24 am
by JS-Support @Userware
We are going to look into this.

Re: DataGrid Column HorizontalAlignment Right ?

Posted: Thu Jul 28, 2016 11:17 pm
by Sesztak
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

Re: DataGrid Column HorizontalAlignment Right ?

Posted: Fri Jul 29, 2016 7:05 am
by JS-Support @Userware
Thank you for the workaround.