I think your code will be helpful on the next step for me, that is to say selecting the correct DataTemplate depending on a property of my data.
What bothers me now is mixing the DataTemplate I had set to my column's CellContentTemplate and the ControlTemplate used in my DataCell's Style.
I think I can solve my problem using a TemplateBinding, but I can't figure out how...
Here is what I have done for now:
1) My DataTemplate:
<conv:RelativeAbsoluteTimeConverter_C x:Key="relativeTimeConverter" />
<DataTemplate x:Key="relativeTimeCellDataTemplate"
x:Name="relativeTimeCellDataTemplate">
<ContentPresenter Content="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type xcdg:Cell}},
Path=DataContext,
Mode=TwoWay,
Converter={StaticResource relativeTimeConverter},
ConverterParameter={StaticResource dataSourceBus}}" />
</DataTemplate>
2) My Column definition:
<xcdg:DataGridControl.Columns>
<xcdg:Column FieldName="Time"
Title="Time (µs)"
ReadOnly="True"
CellContentTemplate="{StaticResource relativeTimeCellDataTemplate}"/>
3) The Style used on my cells:
<Style TargetType="xcdg:DataCell"
BasedOn="{StaticResource DefaultDataCellStyle}"
x:Key="DataCellTextBlockStyle">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="xcdg:DataCell">
<TextBlock VerticalAlignment="Center">
<!-- Here is my problem ! I don't know how to get the Column's CellContentTemplate... -->
<ContentPresenter ContentTemplate="{TemplateBinding ContentTemplate}" />
<!--<ContentPresenter ContentTemplate="{TemplateBinding xcdg:Column.CellContentTemplate}"/>-->
<!--<ContentPresenter ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}" />-->
<!--<ContentPresenter ContentTemplate="{TemplateBinding xcdg:DataCell.ParentColumn.CellContentTemplate}" />-->
</TextBlock>
<ControlTemplate.Resources>
<Style TargetType="{x:Type TextBlock}">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=IsValid}"
Value="False">
<Setter Property="Foreground"
Value="Red" />
<Setter Property="TextDecorations">
<Setter.Value>
<TextDecorationCollection>
<TextDecoration Location="Strikethrough"
PenOffset="0.75" />
</TextDecorationCollection>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</ControlTemplate.Resources>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
If anyone has an idea on how to link my ContentPresenter ContentTemplate on my DataTemplate, that would be great.