Note that there are some explanatory texts on larger screens.

plurals
  1. POConsolidating common WPF Styles
    primarykey
    data
    text
    <p>I have various Style elements in my WPF XAML that are the same except for the data binding property, e.g.:</p> <pre><code>&lt;Style x:Key="HasAlphaStyle" TargetType="TextBlock"&gt; &lt;Style.Triggers&gt; &lt;DataTrigger Binding="{Binding Path=HasAlpha, UpdateSourceTrigger=PropertyChanged}" Value="True"&gt; &lt;Setter Property="Background" Value="Red"/&gt; &lt;Setter Property="Foreground" Value="White"/&gt; &lt;Setter Property="FontWeight" Value="Bold"/&gt; &lt;/DataTrigger&gt; &lt;DataTrigger Binding="{Binding Path=HasAlpha, UpdateSourceTrigger=PropertyChanged}" Value="False"&gt; &lt;Setter Property="Background" Value="LightGreen"/&gt; &lt;Setter Property="Foreground" Value="Black"/&gt; &lt;Setter Property="FontWeight" Value="Normal"/&gt; &lt;/DataTrigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; &lt;Style x:Key="HasBetaStyle" TargetType="TextBlock"&gt; &lt;Style.Triggers&gt; &lt;DataTrigger Binding="{Binding Path=HasBeta, UpdateSourceTrigger=PropertyChanged}" Value="True"&gt; &lt;Setter Property="Background" Value="Red"/&gt; &lt;Setter Property="Foreground" Value="White"/&gt; &lt;Setter Property="FontWeight" Value="Bold"/&gt; &lt;/DataTrigger&gt; &lt;DataTrigger Binding="{Binding Path=HasBeta, UpdateSourceTrigger=PropertyChanged}" Value="False"&gt; &lt;Setter Property="Background" Value="LightGreen"/&gt; &lt;Setter Property="Foreground" Value="Black"/&gt; &lt;Setter Property="FontWeight" Value="Normal"/&gt; &lt;/DataTrigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; </code></pre> <p>The style is applied to a control like:</p> <pre><code>&lt;TextBlock Style="{StaticResource HasAlphaStyle}" .../&gt; </code></pre> <p>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.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload