Best place to understand a WPF control is to look at the Default Template. For the DataGrid it can be found here:
DataGrid Styles and Templates - WPF .NET Framework | Microsoft Learn[
^].
What you are pointing to is the
Select All button in the top-left corner of the
DataGrid
.
Using the link above, that is the
DataGridSelectAllButtonStyle
. It is the very first style found on the page linked above.
<Style TargetType="{x:Type Button}"
x:Key="{ComponentResourceKey ResourceId=DataGridSelectAllButtonStyle,
TypeInTargetAssembly={x:Type DataGrid}}">
</Style>
Do a search of the template and you can see where it is applied. This is the style that you need to modify.
<ControlTemplate TargetType="{x:Type DataGrid}">
<Button Focusable="false"
Command="{x:Static DataGrid.SelectAllCommand}"
Style="{DynamicResource {ComponentResourceKey
ResourceId=DataGridSelectAllButtonStyle,
TypeInTargetAssembly={x:Type DataGrid}}}"
Visibility="{Binding HeadersVisibility,
ConverterParameter={x:Static DataGridHeadersVisibility.All},
Converter={x:Static DataGrid.HeadersVisibilityConverter},
RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}"
Width="{Binding CellsPanelHorizontalOffset,
RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}" />
</ControlTemplate>
So you need to modify the
DataGridSelectAllButtonStyle
and apply a new
ControlTemplate
. There is a link on that page that will direct you on how to create a
ControlTemplate
and a link to a sample at the bottom of the page.