title: Styling columns based on DataGridTemplateColumn in a WPF DataGrid
body: <p>I am using a WPF DataGrid where one of the columns has a requirement to show an "Edit" hyperlink if the row is editable - this is indicated by a boolean flag in the backing model for the row. I was able to achieve this using a DataGridTemplateColumn - no problems. However an additional requirement on the entire row is not to show any highlights when the row is selected (this is a blue background by default). I have been able to achieve this on other columns by defining the DataGridCell style with a transparent background, e.g.</p>
  
  <pre><code>&lt;DataGridTextColumn
      Header="Id"
      Binding="{Binding Path=Id}"
      HeaderStyle="{StaticResource DataGridColumnHeaderStyle}"
      CellStyle="{StaticResource DataGridCellStyle}" /&gt;
  </code></pre>
  
  <p>where DataGridCellStyle is defined as follows:</p>
  
  <pre><code>&lt;Style x:Key="DataGridCellStyle" TargetType="{x:Type DataGridCell}"&gt;
      &lt;Setter Property="Background" Value="Transparent" /&gt;
      ...
  &lt;/Style&gt;
  </code></pre>
  
  <p>However the column in question, a DataGridTemplateColumn, does not offer a "CellStyle" attribute which I can use for turning off selection highlights. So my question is how to set the cell style when using a DataGridTemplateColumn? Here's my implementation of the column which satisfies the first requirement (i.e. showing an "Edit" hyperlink if the row is editable):</p>
  
  <pre><code>&lt;DataGridTemplateColumn
      Header="Actions"
      HeaderStyle="{StaticResource CenterAlignedColumnHeaderStyle}"&gt;
      &lt;DataGridTemplateColumn.CellTemplate&gt;
          &lt;DataTemplate&gt;
              &lt;TextBlock
                  Visibility="{Binding Path=Editable, Converter={StaticResource convVisibility}}"
                  Style="{StaticResource CenterAlignedElementStyle}"&gt;
                      &lt;Hyperlink
                          Command="..."
                          CommandParameter="{Binding}"&gt;
                          &lt;TextBlock Text="Edit" /&gt;
                      &lt;/Hyperlink&gt;
              &lt;/TextBlock&gt;
          &lt;/DataTemplate&gt;
      &lt;/DataGridTemplateColumn.CellTemplate&gt;
  &lt;/DataGridTemplateColumn&gt;
  </code></pre>
  
  <p>Thanks.</p>