选择 cell/row 时更改 cell/row 文本颜色 - DataGrid WPF
Change cell/row text colour when cell/row is selected - DataGrid WPF
选择DataGrid Row时以及它处于不活动选择模式时(已选择并现在单击另一个控件,即文本框)。[= = = = = = = = 14=]
我试过这个(设置单元格样式):
<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>
As it is possible to notice, I tried to do it with triggers, i.e when cell is selected colour my text inside cell with white colour etc,
但显然这是行不通的
My text in DataGrid when cell/row is selected is still black..
试试这个风格
<DataGrid.Resources>
<Style TargetType="{x:Type DataGridCell}">
<Style.Triggers>
<Trigger Property="IsSelected"
Value="True">
<Setter Property="Foreground"
Value="Red" />
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.Resources>
尝试在DataGrid
中添加以下刷机资源:
<DataGrid>
<DataGrid.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="White"/>
<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightTextBrushKey}" Color="White"/>
</DataGrid.Resources>
...
</DataGrid>
应该在 Windows 7 上工作。在 Windows 8 和更高版本上,您将必须覆盖 DataGridRow
.
的控件模板
选择DataGrid Row时以及它处于不活动选择模式时(已选择并现在单击另一个控件,即文本框)。[= = = = = = = = 14=]
我试过这个(设置单元格样式):
<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>
As it is possible to notice, I tried to do it with triggers, i.e when cell is selected colour my text inside cell with white colour etc, 但显然这是行不通的
My text in DataGrid when cell/row is selected is still black..
试试这个风格
<DataGrid.Resources>
<Style TargetType="{x:Type DataGridCell}">
<Style.Triggers>
<Trigger Property="IsSelected"
Value="True">
<Setter Property="Foreground"
Value="Red" />
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.Resources>
尝试在DataGrid
中添加以下刷机资源:
<DataGrid>
<DataGrid.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="White"/>
<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightTextBrushKey}" Color="White"/>
</DataGrid.Resources>
...
</DataGrid>
应该在 Windows 7 上工作。在 Windows 8 和更高版本上,您将必须覆盖 DataGridRow
.