我有一个WPF DataGrid,其中SelectedItem与ViewModel属性绑定。
并且
结果是一样的。当用户单击一行时,它会短暂地闪红,然后回到苍白的灰色,尽管该行实际上仍然被选中。如果他们第二次点击它,它就会变成红色并保持红色。
如果我删除SelectedItem上的绑定,它将按预期工作。如何使其无论绑定如何都能正常工作?
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上的绑定,它将按预期工作。如何使其无论绑定如何都能正常工作?
<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="{DynamicResource {x:Static SystemColors.HighlightColorKey}}"/>
这将使得非活动状态变为活动状态,无论默认情况还是需要更改高亮键。 - Khale_Kitha