【发布时间】:2015-01-18 15:45:27
【问题描述】:
我有一个 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 上的绑定,它会按预期工作。无论绑定如何,我怎样才能使这项工作?
【问题讨论】: