- <Window.Resources>
-
<Style TargetType="DataGrid"> -
<!--拖动改变单元格大小--> -
<Setter Property="CanUserResizeColumns" Value="false"/> -
<!--网格线颜色--> -
<Setter Property="HorizontalGridLinesBrush "> -
<Setter.Value> -
<SolidColorBrush Color="LightBlue"/> -
</Setter.Value> -
</Setter> -
<Setter Property="VerticalGridLinesBrush"> -
<Setter.Value> -
<SolidColorBrush Color="LightBlue"/> -
</Setter.Value> -
</Setter> -
</Style> -
-
<!--标题栏样式--> -
<Style TargetType="DataGridColumnHeader" > -
<Setter Property="Width" Value="50"/> -
<Setter Property="FontSize" Value="14" /> -
<Setter Property="Background" Value="lightBlue" /> -
<!--加粗--> -
<Setter Property="FontWeight" Value="Bold"/> -
</Style> -
-
<!--行样式触发--> -
<!--背景色改变必须先设置cellStyle 因为cellStyle会覆盖rowStyle样式--> -
<Style TargetType="DataGridRow"> -
<Style.Triggers> -
<Trigger Property="IsSelected" Value="True"> -
<Setter Property="BorderBrush" Value="Red" /> -
<Setter Property="BorderThickness" Value="1" /> -
</Trigger> -
<Trigger Property="IsMouseOver" Value="True"> -
<Setter Property="Background" Value="LightGray"/> -
</Trigger> -
</Style.Triggers> -
</Style> -
-
<!--单元格样式触发--> -
<Style TargetType="DataGridCell"> -
<Style.Triggers> -
<Trigger Property="IsSelected" Value="True"> -
<Setter Property="Background" Value="White"/> -
<Setter Property="BorderThickness" Value="0"/> -
<Setter Property="Foreground" Value="Red"/> -
</Trigger> -
</Style.Triggers> -
</Style> - </Window.Resources>
WPF中设置DataGrid的一些样式
最新推荐文章于 2024-08-27 17:00:08 发布