It taking 5 lines to right-align a DataGridTextColumn is bloating my XAML.
How can I put this "right-align code block" into a style and call it from an attribute, e.g. class="rightAlignDataGridTextColumn".
<toolkit:DataGridTextColumn Header="Order Date" Width="Auto"
Binding="{Binding OrderDate, StringFormat='{}{0:dd.MM.yyyy}'}"
IsReadOnly="False">
<toolkit:DataGridTextColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="TextAlignment" Value="Right" />
</Style>
</toolkit:DataGridTextColumn.ElementStyle>
</toolkit:DataGridTextColumn>
<toolkit:DataGridTextColumn Header="Required Date" Width="Auto"
Binding="{Binding RequiredDate, StringFormat='{}{0:dd.MM.yyyy}'}"
IsReadOnly="False">
<toolkit:DataGridTextColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="TextAlignment" Value="Right" />
</Style>
</toolkit:DataGridTextColumn.ElementStyle>
</toolkit:DataGridTextColumn>
<toolkit:DataGridTextColumn Header="Shipped Date" Width="Auto"
Binding="{Binding ShippedDate, StringFormat='{}{0:dd.MM.yyyy}'}"
IsReadOnly="False">
<toolkit:DataGridTextColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="TextAlignment" Value="Right" />
</Style>
</toolkit:DataGridTextColumn.ElementStyle>
</toolkit:DataGridTextColumn>
Declare the Style in a ResourceDictionary, like so:
<Window.Resources>
<Style x:Key="RightAlignStyle" TargetType="{x:Type TextBlock}">
<Setter Property="TextAlignment" Value="Right" />
</Style>
</Window.Resources>
Then reference this style on each DataGridTextColumn
element:
<toolkit:DataGridTextColumn ElementStyle="{StaticResource RightAlignStyle}" ... >
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With