I have a datagrid and want to style its cells. I have 4 columns, 2 are text columns and 2 are custom columns for edit and delete button as shown below. My purpose is to style them differently. When mouse on text columns, cell background will be different than on edit and delete columns. I have a generic Style for DataGrid and have new Style for DataGridCell in it. How to define new style for the edit and delete buttons and set this new style in xaml file ?
Style
<Style TargetType="{x:Type DataGrid}">
<Style.Resources>
<Style TargetType="{x:Type DataGridCell}">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridCell}">
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="{StaticResource ControlBackgroundLine}" />
</Trigger>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="{StaticResource BackgroundSelected}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Style.Resources>
</Style>
XAML
<DataGrid Grid.Row="3" ItemsSource="{Binding deckList}" AutoGenerateColumns="False"
SelectionMode="Single" SelectionUnit="FullRow" Margin="10,10,0,0" >
<DataGrid.Columns>
<DataGridTextColumn Header="Name" Binding="{Binding Path=Name}" ></DataGridTextColumn>
<DataGridTextColumn Header="SurName" Binding="{Binding Path=SurName}"></DataGridTextColumn>
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Width="32">
<Image Source="/KillCard;component/Resources/Images/delete.png" Width="16"></Image>
</Button>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Width="32">
<Image Source="/KillCard;component/Resources/Images/edit.png" Width="16"></Image>
</Button>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>

You can set the
DataGrid.CellStyleproperty to configure cells globally (in the scope of the currentDataGrid):Or, to configure individual cells, set the
DataGridColumn.CellStyleproperty: