我有DataGrid
这样:
<DataGrid AutoGenerateColumns="False" Height="221" HorizontalAlignment="Center" VerticalContentAlignment="Center" HorizontalContentAlignment="Center"
Margin="6,269,0,0" Name="dataGrid1" VerticalAlignment="Center" Width="875" SelectionChanged="dataGrid1_SelectionChanged">
<DataGrid.Columns >
<DataGridTextColumn x:Name="Id" Header="ID" Binding="{Binding Path=Key}" HeaderStyle="">
</DataGridTextColumn>
<DataGridTemplateColumn Header="Image" Width="SizeToCells" IsReadOnly="True" MinWidth="80">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Image Width="16" Height="16" Source="{StaticResource MyImageSource}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
如何以DataGrid Header
为中心?并为它申请风格?
感谢
编辑1):
编写此代码后:
<DataGrid.ColumnHeaderStyle>
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="HorizontalContentAlignment" Value="Center" />
</Style>
</DataGrid.ColumnHeaderStyle>
网格列成为:
为什么?
答案 0 :(得分:17)
为了避免标题折叠的影响,只需以这种方式纠正您的风格:
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="HorizontalContentAlignment" Value="Center" />
答案 1 :(得分:0)
为Datagrid的DatagridColumnHeader添加样式
@ContextConfiguration