Styling columns based on DataGridTemplateColumn in WPF DataGrid
I am using 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 paging model for the row. I was able to achieve this with DataGridTemplateColumn - no problem. However, an additional requirement on the entire row should not show any highlights when the row is selected (by default, this is a blue background). I was able to achieve this in other columns by specifying a DataGridCell style with a transparent background, eg.
<DataGridTextColumn
Header="Id"
Binding="{Binding Path=Id}"
HeaderStyle="{StaticResource DataGridColumnHeaderStyle}"
CellStyle="{StaticResource DataGridCellStyle}" />
where DataGridCellStyle is defined as follows:
<Style x:Key="DataGridCellStyle" TargetType="{x:Type DataGridCell}">
<Setter Property="Background" Value="Transparent" />
...
</Style>
However, this DataGridTemplateColumn does not offer a "CellStyle" attribute that I can use to turn off highlight highlighting. So my question is how to set the cell style when using the DataGridTemplateColumn? Here's my column implementation that satisfies the first requirement (ie, shows an "Edit" hyperlink if the row is editable):
<DataGridTemplateColumn
Header="Actions"
HeaderStyle="{StaticResource CenterAlignedColumnHeaderStyle}">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock
Visibility="{Binding Path=Editable, Converter={StaticResource convVisibility}}"
Style="{StaticResource CenterAlignedElementStyle}">
<Hyperlink
Command="..."
CommandParameter="{Binding}">
<TextBlock Text="Edit" />
</Hyperlink>
</TextBlock>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
Thanks.
a source to share
At least in WPF4 there is a CellStyle for DataGridTemplateColumns: http://msdn.microsoft.com/en-us/library/cc189163.aspx
a source to share