【问题标题】:wpf DataGrid Loses its Row Selection when the focus is lostwpf DataGrid 失去焦点时丢失其行选择
【发布时间】:2012-11-05 21:41:56
【问题描述】:

我在使用 DataGrid 时遇到了一个非常奇怪的行为。我在 DataGridRow 上有以下触发器

<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 失去焦点(例如,我单击窗口上的某个其他按钮),则 Foreground 属性将失去其值,但背景仍与触发器中指定的一样。有没有人遇到过这种行为,或者我上面的代码(或我的应用程序中的其他地方)存在一些问题。上述问题的任何解决方法?

【问题讨论】:

    标签: wpf


    【解决方案1】:

    我使用了 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>
    

    希望它对某人有所帮助!

    【讨论】:

      猜你喜欢
      • 2017-04-04
      • 2016-03-12
      • 2013-04-03
      • 1970-01-01
      • 1970-01-01
      • 2013-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多