I have various Style elements in my WPF XAML that are the same except for the data binding property, e.g.:
<Style x:Key="HasAlphaStyle" TargetType="TextBlock">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=HasAlpha, UpdateSourceTrigger=PropertyChanged}" Value="True">
<Setter Property="Background" Value="Red"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="FontWeight" Value="Bold"/>
</DataTrigger>
<DataTrigger Binding="{Binding Path=HasAlpha, UpdateSourceTrigger=PropertyChanged}" Value="False">
<Setter Property="Background" Value="LightGreen"/>
<Setter Property="Foreground" Value="Black"/>
<Setter Property="FontWeight" Value="Normal"/>
</DataTrigger>
</Style.Triggers>
</Style>
<Style x:Key="HasBetaStyle" TargetType="TextBlock">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=HasBeta, UpdateSourceTrigger=PropertyChanged}" Value="True">
<Setter Property="Background" Value="Red"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="FontWeight" Value="Bold"/>
</DataTrigger>
<DataTrigger Binding="{Binding Path=HasBeta, UpdateSourceTrigger=PropertyChanged}" Value="False">
<Setter Property="Background" Value="LightGreen"/>
<Setter Property="Foreground" Value="Black"/>
<Setter Property="FontWeight" Value="Normal"/>
</DataTrigger>
</Style.Triggers>
</Style>
The style is applied to a control like:
<TextBlock Style="{StaticResource HasAlphaStyle}" .../>
Is there a way I can consolidate my HasAlphaStyle and HasBetaStyle so that the property setters don't have to be duplicated? The only difference between the two is the Binding Path to the property.