fix<DataGrid>:修复 DataGrid 在失去焦点之后单元格颜色变化问题,现在选中行失去焦点后仍然高亮

This commit is contained in:
ZCShou 2021-04-08 09:52:53 +08:00
parent 47c70669cd
commit 81ebf0cdf1

View file

@ -3,6 +3,22 @@
<Style x:Key="Style.DataGridCell" TargetType="{x:Type DataGridCell}"> <Style x:Key="Style.DataGridCell" TargetType="{x:Type DataGridCell}">
<Setter Property="BorderThickness" Value="0"/> <Setter Property="BorderThickness" Value="0"/>
<Style.Triggers>
<Trigger Property="IsSelected" Value="true">
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" />
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}" />
<Setter Property="BorderBrush" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" />
</Trigger>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding IsSelected, RelativeSource={RelativeSource Self}}" Value="True" />
<Condition Binding="{Binding IsKeyboardFocusWithin, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}, Mode=FindAncestor}}" Value="False" />
</MultiDataTrigger.Conditions>
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" />
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}" />
<Setter Property="BorderBrush" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" />
</MultiDataTrigger>
</Style.Triggers>
</Style> </Style>
<Style x:Key="Style.DataGridRow" TargetType="{x:Type DataGridRow}"> <Style x:Key="Style.DataGridRow" TargetType="{x:Type DataGridRow}">
@ -14,12 +30,8 @@
</Trigger> </Trigger>
</Style.Triggers> </Style.Triggers>
</Style> </Style>
<Style TargetType="{x:Type DataGrid}"> <Style TargetType="{x:Type DataGrid}">
<Style.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="{x:Static SystemColors.HighlightColor}"/>
</Style.Resources>
<Setter Property="IsReadOnly" Value="True"/> <Setter Property="IsReadOnly" Value="True"/>
<Setter Property="AutoGenerateColumns" Value="False"/> <Setter Property="AutoGenerateColumns" Value="False"/>
<Setter Property="CanUserAddRows" Value="False"/> <Setter Property="CanUserAddRows" Value="False"/>