How to suppress the selection border of a DataGrid cell?

I tried to set the border style as suggested here. Disable the current border of the DataGrid cells in FullRow selection mode , but this does not do it completely. Disables the selection of the cell border when you select with the mouse, but when you make a selection using the keyboard, the dotted border of the cell is still saved. Any suggestions?

+4
source share
2 answers

the dotted line you see is the FocusedVisualStyle cell

you need to redefine it to be empty.

2 options (one of them should be correct, but since I did not have time to try, I do not know which one)

  • VisualStyle is installed directly in the cell

this means that you must set it through the CellStyle property:

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

or if you want to follow the recommendations on MS templates:

 <DataGrid.Resources> <!--CellFocusVisual--> <Style x:Key="CellFocusVisual"> <Setter Property="Control.Template"> <Setter.Value> <ControlTemplate> <Border> <Rectangle StrokeThickness="0" Stroke="#00000000" StrokeDashArray="1 2"/> </Border> </ControlTemplate> </Setter.Value> </Setter> </Style> </DataGrid.Resources> <DataGrid.CellStyle> <Style TargetType="DataGridCell"> <Setter Property="FocusVisualStyle" Value="{StaticResource CellFocusVisual}"/> </Style> </DataGrid.CellStyle> 

(so you can see how this is done)

  • another option: this is done using ElementStyle or EditingElementStyle

it has more hasle there because ElementStyle and EditingElementStyle defined in a column, which means you need to edit each column of ElementStyle and EditingElementStyle .

but basically it’s the same thing: you set FocusVisualStyle to null or the style defined above through ElementStyle and / or EditingElementStyle in each column

+10
source

You can set Focusable to False.

 <DataGrid ... SelectionUnit="FullRow"> <DataGrid.CellStyle> <Style TargetType="DataGridCell"> <Setter Property="BorderThickness" Value="0"/> <Setter Property="Focusable" Value="False"/> </Style> </DataGrid.CellStyle> <!-- ... --> </DataGrid> 

Note that if you create a DataGridCell.Focusable false, then switching to the datagrid using the up / down arrow keys will not work.

+9
source

Source: https://habr.com/ru/post/1345661/


All Articles