How to set the border for a WPF DataGrid Row which is currently having the focus

12,106

Solution 1

Add this to DataGridRow's style (either using Resources, or by setting 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>

Solution 2

Try IsKeyboardFocusWithin Property

    <Style.Triggers>
        <Trigger Property="IsKeyboardFocusWithin"
                 Value="True">
            <Setter Property="BorderBrush"
                    Value="Red" />
        </Trigger>
    </Style.Triggers>
Share:
12,106
ksvimal
Author by

ksvimal

Updated on June 04, 2022

Comments

  • ksvimal
    ksvimal about 2 years

    I want to set the border for a DataGrid Row which is currently having the focus. But not the seleced row because when the Multi selection is enabled for the datagrid then there is a chance that multiple rows can be selected.

    I need a solution in XAML

    Thanks in advance!

    • svick
      svick almost 14 years
      BTW, you should mark the answers that answered your questions as such.
  • ksvimal
    ksvimal almost 14 years
    Hi svick, I have already tried this, but the problem here is if i keep the focus on a row through tab then i m getting the border but if i tabe once again then focus goes to the cell, here i m losing the border though still it remains a current row. Hope this is clear
  • Dan J
    Dan J almost 14 years
    Perhaps triggering on the row's IsSelected property rather than the IsFocused property would work?