DataGrid RowHeaderの行番号を中央揃えにするには、カスタムRowHeaderStyleテンプレートを使用します。
デザインモードでDataGridを右クリックし、[追加テンプレートの編集] - > [RowHeaderStyleの編集] - > [コピーの編集]を選択して、Visual Studio 2012以降でデフォルトテンプレートを生成できます。新しいスタイルリソースに名前を付け、それを生成する場所を選択したら、必要に応じて生成されたXAMLテンプレートを変更できます。
のWindowsの各リビジョンがわずかに異なるテンプレートを生成しますので、しかし、上記のWindows 8とで、すべてあなたがしなければならないテーマで
DataGridHeaderBorder
のStackPanelに設定されている:
たHorizontalAlignment = "センターにDataGridHeaderBorder "
Windows 10 Fall Update DataHrid RowHeaderStyleテンプレートのスニペットを追加します。
<DataGrid.Resources>
<BooleanToVisibilityConverter x:Key="bool2VisibilityConverter"/>
<Style x:Key="RowHeaderGripperStyle" TargetType="{x:Type Thumb}">
<Setter Property="Height" Value="8"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Cursor" Value="SizeNS"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Thumb}">
<Border Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="DataGridRowHeaderStyle1" TargetType="{x:Type DataGridRowHeader}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridRowHeader}">
<Grid>
<Themes:DataGridHeaderBorder BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" IsPressed="{TemplateBinding IsPressed}" IsHovered="{TemplateBinding IsMouseOver}" IsSelected="{TemplateBinding IsRowSelected}" Orientation="Horizontal" Padding="{TemplateBinding Padding}" SeparatorBrush="{TemplateBinding SeparatorBrush}" SeparatorVisibility="{TemplateBinding SeparatorVisibility}">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<ContentPresenter RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center"/>
<Control SnapsToDevicePixels="false" Template="{Binding ValidationErrorTemplate, RelativeSource={RelativeSource AncestorType={x:Type DataGridRow}}}" Visibility="{Binding (Validation.HasError), Converter={StaticResource bool2VisibilityConverter}, RelativeSource={RelativeSource AncestorType={x:Type DataGridRow}}}"/>
</StackPanel>
</Themes:DataGridHeaderBorder>
<Thumb x:Name="PART_TopHeaderGripper" Style="{StaticResource RowHeaderGripperStyle}" VerticalAlignment="Top"/>
<Thumb x:Name="PART_BottomHeaderGripper" Style="{StaticResource RowHeaderGripperStyle}" VerticalAlignment="Bottom"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</DataGrid.Resources>
のような行ヘッダのための単純なスタイル。 –