【问题标题】:How to set the border for a WPF DataGrid Row which is currently having the focus如何为当前具有焦点的 WPF DataGrid Row 设置边框
【发布时间】:2011-04-06 04:49:11
【问题描述】:

我想为当前具有焦点的 DataGrid Row 设置边框。但不是选定的行,因为当为数据网格启用多选时,就有可能选择多行。

我需要 XAML 中的解决方案

提前致谢!

【问题讨论】:

  • 顺便说一句,您应该标记回答您问题的答案。

标签: wpf wpf-controls wpftoolkit wpfdatagrid


【解决方案1】:

将此添加到DataGridRow 的样式中(使用资源,或通过设置DataGrid.RowStyle):

<Style TargetType="DataGridRow">
    <Style.Triggers>
        <Trigger Property="IsFocused" Value="true">
            <Setter Property="BorderBrush" Value="Red" />
            <Setter Property="BorderThickness" Value="1" />
        </Trigger>
    </Style.Triggers>
</Style>

【讨论】:

  • 嗨 svick,我已经尝试过了,但这里的问题是,如果我通过选项卡将焦点保持在一行上,那么我会获得边框,但如果我再次使用 tabe,那么焦点会转到单元格,我在这里失去了边界,尽管它仍然是当前行。希望这很清楚
  • 也许触发行的IsSelected 属性而不是IsFocused 属性会起作用?
【解决方案2】:

试试 IsKeyboardFocusWithin 属性

    <Style.Triggers>
        <Trigger Property="IsKeyboardFocusWithin"
                 Value="True">
            <Setter Property="BorderBrush"
                    Value="Red" />
        </Trigger>
    </Style.Triggers>

【讨论】:

    猜你喜欢
    • 2011-12-03
    • 1970-01-01
    • 2011-10-25
    • 1970-01-01
    • 2016-05-11
    • 2023-03-25
    • 1970-01-01
    • 1970-01-01
    • 2011-11-25
    相关资源
    最近更新 更多