How can you set the alignment of cell content in a Silverlight DataGrid?
The approach given for WPF DataGrids at this other question doesn't seem to work in Silverlight.
How can you set the alignment of cell content in a Silverlight DataGrid?
The approach given for WPF DataGrids at this other question doesn't seem to work in Silverlight.
In C#:
var rightCellStyle = new Style(typeof(DataGridCell));
rightCellStyle.Setters.Add(new Setter(
Control.HorizontalContentAlignmentProperty,
HorizontalAlignment.Right));
dataGrid.Columns.Add(new DataGridTextColumn {
Binding = /* binding */,
Header = /* header */,
CellStyle = rightCellStyle;
});
Or in XAML...
Add XMLNS:
xmlns:sdk="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
Add this resource:
<Style x:Key="RightCellStyle" TargetType="sdk:DataGridCell">
<Setter Property="HorizontalContentAlignment" Value="Right" />
</Style>
Set on a column like this:
<sdk:DataGridTextColumn Header="Header" Binding="{Binding Binding}"
CellStyle="{StaticResource RightCellStyle}" />
Just need to right align the DataGridCell
, like this,
<sdk:DataGrid Margin="104,82,139,71" AutoGenerateColumns="False" ItemsSource="{Binding Collection}">
<sdk:DataGrid.CellStyle>
<Style TargetType="sdk:DataGridCell">
<Setter Property="HorizontalContentAlignment" Value="Right"/>
</Style>
</sdk:DataGrid.CellStyle>
I think you want the HorizontalContentAlignment. If its in a style:
<Setter Property="HorizontalContentAlignment" Value="Center" />