WPF DataGrid选择行样式 [英] WPF DataGrid selected row style
本文介绍了WPF DataGrid选择行样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到一个非常愚蠢的问题 - 需要在WPF DataGrid中选择行的样式。
I'm stuck with one very stupid problem - need to style selected row in WPF DataGrid.
我想显示一个带有蓝色边框的矩形,而不是仅使用一些颜色填充整行。
I want to show a rectangle with blue border instead of just filling entire row with some color.
任何想法如何实现?
推荐答案
使用 CellStyle
和 RowStyle
在 DataGrid
上。 DataGridCell
和 DataGridRow
都具有可以使用的 IsSelected
属性在触发器
中找出是否被选中。
Use CellStyle
and RowStyle
on DataGrid
. DataGridCell
and DataGridRow
both have IsSelected
property that can be used in a Trigger
to find out if they are selected.
下面的东西应该做到这一点:
Something like following should do the trick:
<DataGrid.CellStyle>
<Style TargetType="DataGridCell">
<Style.Triggers>
<Trigger Property="IsSelected"
Value="True">
<Setter Property="Background"
Value="White" />
<Setter Property="Foreground"
Value="Black" />
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.CellStyle>
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Style.Triggers>
<Trigger Property="IsSelected"
Value="True">
<Setter Property="BorderBrush"
Value="Blue" />
<Setter Property="BorderThickness"
Value="2" />
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.RowStyle>
只要玩,直到你正确的。
Just play around until you get it right.
这篇关于WPF DataGrid选择行样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文