【发布时间】:2017-08-07 11:45:43
【问题描述】:
如何在选择 DataGrid Row 时以及当它处于非活动选择模式时(它被选中并且现在用户单击另一个控件,即文本框)时,我的行中的文本保持颜色,例如白色。
我试过这个(设置单元格样式):
<DataGrid.CellStyle>
<StaticResource ResourceKey="DataGridCentering"/>
</DataGrid.CellStyle>
我在 App.Xaml 中所说的:
<Style x:Key="DataGridCentering" TargetType="{x:Type DataGridCell}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridCell}">
<Grid Background="{TemplateBinding Background}">
<ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Foreground" Value="White"/>
</Trigger>
</Style.Triggers>
</Style>
因为可以注意到,我尝试用触发器进行,即,当Cell选择颜色时,我的文本用白色颜色等, 但不知不觉这是行不通的
My text in DataGrid when cell/row is selected is still black..
【问题讨论】:
标签: c# wpf colors cell wpfdatagrid