WPF学习笔记-DataGrid列头标题居中及列中文本居中

列头标题居中

1 <Style x:Key="ColumnHeaderStyleC" TargetType="DataGridColumnHeader">
2     <Setter Property="HorizontalContentAlignment" Value="Center"/>
3     <Style.Triggers>
4          <Trigger Property="IsMouseOver" Value="True">
5                <Setter Property="ToolTip" Value="Click to sort."/>
6          </Trigger>
7     </Style.Triggers>
8 </Style>

使用

<DataGrid  Name="AlarmDataDG" ColumnHeaderStyle="{DynamicResource ColumnHeaderStyleC}" BeginningEdit="AlarmDataDG_BeginningEdit" CellEditEnding="AlarmDataDG_CellEditEnding">

列中文本(DataGridTemplateColumn)

1 <DataGridTemplateColumn Header="序号" Visibility="Hidden">
2    <DataGridTemplateColumn.CellTemplate>
3           <DataTemplate>
4                <TextBlock Text="{Binding Path=RowId}" HorizontalAlignment="Center"/>
5           </DataTemplate>
6    </DataGridTemplateColumn.CellTemplate>
7 </DataGridTemplateColumn>

DataGridTextColumn 设置ElementStyle

参考https://www.cnblogs.com/peasana/archive/2012/07/11/2586031.html

posted @ 2018-12-17 17:44  供销社小翠  阅读(4412)  评论(0编辑  收藏  举报