[英]WPF DataGrid disabled row Foreground color not beeing set
I face a problem with WPF DataGrid. 我遇到了WPF DataGrid的问题。
I want to set the Foreground
value of a disabled DataGrid
row, but the Foreground
stays always gray. 我想设置禁用的DataGrid
行的“ Foreground
值,但“ Foreground
始终保持灰色。
Here is the code I use: 这是我使用的代码:
<DataGrid.RowStyle>
<Style TargetType="{x:Type DataGridRow}">
<EventSetter Event="MouseDoubleClick" Handler="DataGridRowDoubleClick" />
<Setter Property="IsEnabled" Value="{Binding Path=IsMD4Valid}" />
<Setter Property="IsHitTestVisible" Value="{Binding Path=IsMD4Valid}" />
<Style.Triggers>
<DataTrigger Binding="{Binding State}" Value="Added">
<Setter Property="Background" Value="DarkGreen"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="FontWeight" Value="Bold"/>
</DataTrigger>
<DataTrigger Binding="{Binding State}" Value="Changed">
<Setter Property="Background" Value="DarkBlue"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="FontWeight" Value="Bold"/>
</DataTrigger>
<DataTrigger Binding="{Binding State}" Value="Deleted">
<Setter Property="IsEnabled" Value="false" />
<Setter Property="IsHitTestVisible" Value="false" />
<Setter Property="Background" Value="DarkRed"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="FontWeight" Value="Bold"/>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGrid.RowStyle>
Added
, Changed
and Deleted
are just enum values. Added
, Changed
和Deleted
只是枚举值。
Here is what I get: 这是我得到的:
As you can see, the Background
is applied, but the Foreground
not (for row with Deleted
State) 如您所见, Background
被应用,但Foreground
未被应用(对于具有“ Deleted
状态”的行)
Define a custom DataGridCell
style: 定义自定义DataGridCell
样式:
<DataGrid.CellStyle>
<Style TargetType="{x:Type DataGridCell}">
<Style.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="{Binding Foreground, RelativeSource={RelativeSource AncestorType=DataGridRow}}"/>
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.CellStyle>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.