当焦点丢失时,wpf DataGrid将丢失其行选择
我在DataGrid中遇到了一个非常奇怪的行为。我在DataGridRow上有以下触发器当焦点丢失时,wpf DataGrid将丢失其行选择,wpf,Wpf,我在DataGrid中遇到了一个非常奇怪的行为。我在DataGridRow上有以下触发器 <Style TargetType="{x:Type DataGridRow}"> <Style.Triggers> <Trigger Property="IsSelected" Value="True"> <Setter Property="Background" Value="{StaticResource Sel
<Style TargetType="{x:Type DataGridRow}">
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="{StaticResource SelectionBackgroundBrush}"/>
<Setter Property="Foreground" Value="White"/>
</Trigger>
</Style.Triggers>
</Style>
最初,当选择行时,我从上面的触发器获取行为。但是,在选择之后,如果DataGrid失去焦点(例如,我单击窗口上的某个其他按钮),前台属性将失去其值,但背景仍保持在触发器中指定的状态。有没有人遇到过这种行为,或者我上面的代码(或者我的应用程序中的其他地方)有问题。上述问题有什么解决方法吗?我使用了DataGridCell而不是DataGridRow,它适合我
<Style TargetType="{x:Type DataGridCell}">
<Style.Triggers>
<Trigger Property="DataGridCell.IsSelected" Value="True">
<Setter Property="BorderBrush" Value="#CCDAFF" />
<Setter Property="Background" Value="#3399ff"/>
<Setter Property="Foreground" Value="White"/>
</Trigger>
</Style.Triggers>
</Style>
希望它能帮助别人