Here is how its done. You use a ContentControl
and specify a ControlTemplate
for it as a static resource:-
<Grid.Resources>
<ControlTemplate x:Key="CommonTextBlock" TargetType="ContentControl">
<TextBlock Opacity="{Binding SomeOpacity}" Text="{TemplateBinding Content}" />
</ControlTemplate>
<Grid.Resource>
<ContentControl Content="{Binding SomeTextValue}" Template="{StaticResource CommonTextBlock}" />
<ContentControl Content="{Binding SomeOtherTextValue}" Template="{StaticResource CommonTextBlock}" />
Now you can bung as may other properties with bindings in to the Control Template as you want.
This approach could be extended to Style
:-
<Grid.Resources>
<ControlTemplate x:Key="CommonTextBlock" TargetType="ContentControl">
<TextBlock Opacity="{Binding SomeOpacity}" Text="{TemplateBinding Content}" />
</ControlTemplate>
<Style x:Key="CommonTextBlockStyle" TargetType="ContentControl">
<Setter Property="Template" Value="{StaticResource CommonTextBlock}" />
<Setter Property="Foreground" Value="Blue" />
</Style>
<Grid.Resource>
<ContentControl Content="{Binding SomeTextValue}" Style="{StaticResource CommonTextBlockStyle}" />
<ContentControl Content="{Binding SomeOtherTextValue}" Style="{StaticResource CommonTextBlockStyle}" />
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…