Bob Tway
Bob Tway

Reputation: 9613

Removing box / border around selected cell contents in WPF DataGrid

Trying to restyle a WPF datagrid. Almost where I need to be, except for one peculiarity: when selecting a row, the contents of all the cells are surrounded by a white border.

enter image description here

I'm at a loss as to how to get rid of this. At the moment, my styling looks like this:

<Style TargetType="{x:Type DataGridRow}">
    <Setter Property="Background" Value="Transparent" />
    <Setter Property="BorderBrush" Value="Transparent" />
    <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
    <Style.Triggers>
        <Trigger Property="IsSelected" Value="True">
            <Setter Property="Background" Value="#3CACDC" />
            <Setter Property="Foreground" Value="White" />
        </Trigger>
        <Trigger Property="IsMouseOver" Value="True">
            <Setter Property="Background" Value="#90C8E0" />
        </Trigger>
    </Style.Triggers>
</Style>

Plus DataGridCell has an almost identical style set.

It's not clear whether the question How to suppress DataGrid cell selection border? is asking the same question, but the accepted solution of setting FocusVisualStyle to Null doesn't remove the border. It does, however, change the style:

enter image description here

How can I get ride of that border?

Upvotes: 1

Views: 2669

Answers (1)

Justin CI
Justin CI

Reputation: 2741

I think you can try styling DataGridCell style

   <DataGrid.CellStyle>
    <Style TargetType="DataGridCell">
        <Setter Property="BorderThickness" Value="0"/>          
        <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
    </Style>
  </DataGrid.CellStyle>

Upvotes: 3

Related Questions