DataGrid的Header风格(按比例显示列、居中显示)已讲解,但并不能使得DataGrid的内容居中显示。其余暂未用到,列使用DataGridTextColumn显示文字时,可添加表格元素风格,设置文字居中显示。
列DataGridTextColumn被选中时,若点击其余地方,可自定义设置DataGrid的非活动状态颜色风格。ide
<!-- DataGridTextColumn 文字居中 --> <Style x:Key="CenterAlignmentStyle" TargetType="TextBlock"> <Setter Property="TextAlignment" Value="Center"/> <Setter Property="VerticalAlignment" Value="Center"/> </Style>
二、选中时失去活动状态颜色设置code