I have 8 different XAML DataTemplates that are all very similar. Here are 2 of them:
<DataTemplate x:Key="ConflictFieldStringCellContentTemplate">
<StackPanel>
<TextBlock Text="{Binding ClientVersion.Value}"
Foreground="{Binding Path=Mismatch, Converter={StaticResource mismatchBoolToBrushConverter}}" />
<Label Background="LightGray" Height="1" Margin="0, 4, -4, 2"></Label>
<TextBlock Text="{Binding ServerVersion.Value}"
Foreground="{Binding Path=Mismatch, Converter={StaticResource mismatchBoolToBrushConverter}}"/>
</StackPanel>
</DataTemplate>
<DataTemplate x:Key="ConflictFieldStringArrayCellContentTemplate">
<StackPanel>
<TextBlock Text="{Binding ClientVersion.Value, Converter={StaticResource stringArrayToCommaDelimitedStringConverter}}"
Foreground="{Binding Path=Mismatch, Converter={StaticResource mismatchBoolToBrushConverter}}"/>
<Label Background="LightGray" Height="1" Margin="0, 4, -4, 2"></Label>
<TextBlock Text="{Binding ServerVersion.Value, Converter={StaticResource stringArrayToCommaDelimitedStringConverter}}"
Foreground="{Binding Path=Mismatch, Converter={StaticResource mismatchBoolToBrushConverter}}"/>
</StackPanel>
</DataTemplate>
As you can see, the only difference is that they use a different Converter for the Binding of the Text property of the TextBlock. Is there any way for me to factor out the commonalities of these two DataTemplates? I have 6 more and updating them is getting very tedious, because everything is identical except for the Converter for the Binding of the Text property.
Is there a way to somehow factor this out into one template which can be parameterized somehow? Something like this would be cool (pseudo-code):
<DataTemplate x:Key="BaseCellContentTemplate">
<StackPanel>
<TextBlock Text="{??}"
Foreground="{Binding Path=Mismatch, Converter={StaticResource mismatchBoolToBrushConverter}}" />
<Label Background="LightGray" Height="1" Margin="0, 4, -4, 2"></Label>
<TextBlock Text="{Binding ServerVersion.Value}"
Foreground="{Binding Path=Mismatch, Converter={StaticResource mismatchBoolToBrushConverter}}"/>
</StackPanel>
</DataTemplate>
<DataTemplate x:Key="ConflictFieldStringCellContentTemplate" BaseTemplate="BaseCellContentTemplate">
<??>{Binding ClientVersion.Value}</??>
</DataTemplate>
<DataTemplate x:Key="ConflictFieldStringArrayCellContentTemplate" BaseTemplate="BaseCellContentTemplate">
<??>{Binding ClientVersion.Value, Converter={StaticResource stringArrayToCommaDelimitedStringConverter}}</??>
</DataTemplate>