Inheritance / Database Based

I have a DataTemplate that I use in my WPF application -

 <DataTemplate x:Key="mattersTemplate"> <Border Name="border" BorderBrush="Aqua" BorderThickness="1" Padding="5" Margin="5"> <Grid> <Grid.RowDefinitions> <RowDefinition/> <RowDefinition/> <RowDefinition/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition /> <ColumnDefinition /> </Grid.ColumnDefinitions> <TextBlock Grid.Row="0" Grid.Column="0" Text="FileRef:"/> <TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding Path=FileRef}" /> <TextBlock Grid.Row="1" Grid.Column="0" Text="Description:"/> <TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding Path=Description}"/> <TextBlock Grid.Row="2" Grid.Column="0" Text="Priority:"/> <TextBlock Grid.Row="2" Grid.Column="1" Text="{Binding Path=Priority}"/> </Grid> </Border> </DataTemplate> 

Then I (in the DocumentSetTemplateSelector class) determine which template to use;

What I would like to know is; Create 4 more templates that inherit this template above, and then allow you to rewrite some attributes;

Example (this template inherits from the above class) - so they look the same:

 <DataTemplate x:Key="documentSet_Accounting"> <ContentPresenter Content="{Binding mattersTemplate}" ContentTemplate="{StaticResource mattersTemplate}"> </ContentPresenter> </DataTemplate> 

I would like there to be a style attached to this (if possible) in order to get this effect;

 <DataTemplate x:Key="documentSet_Accounting"> <ContentPresenter fontsize="20" Content="{Binding mattersTemplate}" ContentTemplate="{StaticResource mattersTemplate}"> </ContentPresenter> </DataTemplate> 

or

 <DataTemplate x:Key="documentSet_Accounting"> <ContentPresenter Style="AccountingStyle" Content="{Binding mattersTemplate}" ContentTemplate="{StaticResource mattersTemplate}"> </ContentPresenter> </DataTemplate> 
+4
source share
1 answer

What about using style inheritance inside templates rather than template inheritance?

 <Style x:Key="mattersTemplateStyle"> <Setter Property="TextBlock.Foreground" Value="Green"/> </Style> <Style x:Key="documentSet_AccountingStyle" BasedOn="{StaticResource mattersTemplateStyle}"> <Setter Property="TextBlock.FontSize" Value="20"/> </Style> <DataTemplate x:Key="mattersTemplate"> <Border Name="border" BorderBrush="Aqua" BorderThickness="1" Padding="5" Margin="5"> <Grid Style="{StaticResource mattersTemplateStyle}"> [...] </Grid> </Border> </DataTemplate> <DataTemplate x:Key="documentSet_Accounting"> <Grid Style="{StaticResource documentSet_AccountingStyle}"> <ContentPresenter Content="{Binding mattersTemplate}" ContentTemplate="{StaticResource mattersTemplate}"></ContentPresenter> </Grid> </DataTemplate> 
+1
source

All Articles