Search code examples
c#wpfdatagrid

wpf datagrid - how to remove black selected border?


I need help, when I click at datagrid at cell, I want to select all line like in image (please look at image), but without black border. how to disable, or change color to transparent? I tried this:

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

but don't work. nothing changes.


Solution

  • You need to style the selected cell not just cells. To do so you need to write this inside your style tag:

    <Style.Triggers>
       <Trigger Property="IsSelected" Value="True">
          <Setter Property="BorderThickness" Value="0"/>
        </Trigger>
    </Style.Triggers>
    

    All you need was using Triggers hope it will work for you. Also you can change background for selected cell or whatever property you want.