title: WPF DataGridTemplateColumn background color not changing on datagrid row selected
body: <p>I have below WPF Toolkit DataGrid. I have created a custom column using DataGridTemplateColumn which contains a toggle button (without text).</p>
  
  <p>When datagrid row is selected, toggle button background color is correctly changed with the same color as row selection but the cell's background is not changing the color, it remains white. Why?</p>
  
  <p>This is the appearance of the DataGridTemplateColumn column before and after row selection.</p>
  
  <p>Before:
  <a href="https://i.stack.imgur.com/QtDAU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QtDAU.png" alt="enter image description here"></a></p>
  
  <p>After:
  <a href="https://i.stack.imgur.com/Gnmk0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Gnmk0.png" alt="enter image description here"></a></p>
  
  <p>Here the code:</p>
  
  <pre><code>&lt;UserControl.Resources&gt;        
      &lt;ResourceDictionary&gt;
  
          &lt;!-- Body content datagrid cell vertical centering --&gt;
          &lt;Style x:Key="Body_Content_DataGrid_Centering" TargetType="{x:Type dg:DataGridCell}"&gt;
              &lt;Setter Property="Template"&gt;
                  &lt;Setter.Value&gt;
                      &lt;ControlTemplate TargetType="{x:Type dg:DataGridCell}"&gt;
                          &lt;Grid Background="{TemplateBinding Background}"&gt;
                              &lt;ContentPresenter VerticalAlignment="Center" /&gt;
                          &lt;/Grid&gt;
                      &lt;/ControlTemplate&gt;
                  &lt;/Setter.Value&gt;
              &lt;/Setter&gt;
          &lt;/Style&gt;
      &lt;/ResourceDictionary&gt;
  &lt;/UserControl.Resources&gt;
  
  &lt;!-- Other Stuff --&gt;
  
  &lt;dg:DataGrid x:Name="MyDg"   
               ItemsSource="{Binding Path=ListOfItems}"
               Margin="3 5 5 5"
               AutoGenerateColumns="False"
               CanUserAddRows="False" CanUserResizeRows="False"
               SelectionMode="Single" 
               SelectedItem="{Binding Path=MySelectedItem}"
               ColumnWidth="*"
               AlternationCount="2" 
               Focusable="False" SelectionUnit="FullRow"
               CellStyle="{StaticResource Body_Content_DataGrid_Centering}"&gt;
  
      &lt;dg:DataGrid.Columns&gt;
  
          &lt;dg:DataGridTemplateColumn Header="Selection" Width="Auto" CanUserResize="False"&gt;
              &lt;dg:DataGridTemplateColumn.CellStyle&gt;
                  &lt;Style TargetType="dg:DataGridCell"&gt;
                      &lt;Setter Property="HorizontalAlignment"  Value="Center"/&gt;
                  &lt;/Style&gt;
              &lt;/dg:DataGridTemplateColumn.CellStyle&gt;
              &lt;dg:DataGridTemplateColumn.CellTemplate&gt;
                  &lt;DataTemplate&gt;
                      &lt;ToggleButton Content="" IsChecked="{Binding Path=IsSelected}"&gt;
                          &lt;ToggleButton.Template&gt;
                              &lt;ControlTemplate TargetType="{x:Type ToggleButton}"&gt;
                                  &lt;StackPanel Orientation="Horizontal"&gt;
                                      &lt;Image MaxWidth="32" MaxHeight="32"&gt;
                                          &lt;Image.Style&gt;
                                              &lt;Style&gt;
                                                  &lt;Setter Property="Image.Source" Value="/My.Graphics;component/PNG/Unchecked.png" /&gt;
                                                  &lt;Style.Triggers&gt;
                                                      &lt;DataTrigger Binding="{Binding IsChecked, 
                                                                             RelativeSource={RelativeSource  Mode=FindAncestor, 
                                                                                             AncestorType={x:Type ToggleButton}}}" Value="True"&gt;
                                                          &lt;Setter Property="Image.Source" Value="/My.Graphics;component/PNG/Checked.png" /&gt;
                                                      &lt;/DataTrigger&gt;
                                                  &lt;/Style.Triggers&gt;
                                              &lt;/Style&gt;
                                          &lt;/Image.Style&gt;
                                      &lt;/Image&gt;
                                   &lt;!--   &lt;ContentPresenter Content="{TemplateBinding Content}" Margin="0,0,0,0" /&gt;--&gt;
                                  &lt;/StackPanel&gt;
                              &lt;/ControlTemplate&gt;
                          &lt;/ToggleButton.Template&gt;
                      &lt;/ToggleButton&gt;
                  &lt;/DataTemplate&gt;
              &lt;/dg:DataGridTemplateColumn.CellTemplate&gt;
          &lt;/dg:DataGridTemplateColumn&gt;
       &lt;/dg:DataGrid.Columns&gt;
  &lt;/dg:DataGrid&gt;
  </code></pre>