我有一个WPF DataGrid,其中SelectedItem绑定到ViewModel属性。
SelectedItem="{Binding DataContext.SelectedBooking, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"
如果用户单击“行”并将其选中,唯一的视觉提示是该行的灰色背景变得非常浅。我需要使这一点更加明显,因此我尝试分别添加它们:
<DataGrid.RowStyle>
<Style TargetType="{x:Type DataGridRow}">
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Foreground" Value="Red"/>
<Setter Property="Background" Value="Red" />
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.RowStyle>
和
<DataGrid.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Red"/>
</DataGrid.Resources>
结果是一样的。当用户单击行时,它会非常短暂地闪烁红色,然后返回到浅灰色,尽管该行实际上仍保持为选中状态。如果他们第二次单击它,它将变为红色并保持红色。
如果我删除SelectedItem上的Binding,它将按预期工作。无论绑定如何,如何使这项工作有效?
我自己浏览了SystemColors的Intellisense,找到了答案。您还可以覆盖一个InactiveSelection笔刷。
<DataGrid.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Red"/>
<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="Red"/>
</DataGrid.Resources>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句