I'm working in XAML, with a bunch of TextBlock controls, who all had a fix style, called "OvenPalStyle", which looked as follows:
<Style x:Key="OvenPalStyle" TargetType="TextBlock">
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="FontSize" Value="14"/>
<Setter Property="FontWeight" Value="Bold"/>
</Style>
That style was used by a bunch of TextBlock objects, as follows:
<TextBlock x:Name="T_7" Tag="" Style="{DynamicResource OvenPalStyle}">
I would like to make this variable, based on some input value, as follows:
<TextBlock x:Name="T_7" Tag="">
<TextBlock.Style>
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="FontSize" Value="14"/>
<Setter Property="FontWeight" Value="Bold"/>
<Style.Trigger>
<DataTrigger Binding="{Binding MinutenGewarmd, Converter={converters:IsStrictlyPositiveAndLowerThan 1200}}" Value="True">
<Setter Property="Foreground" Value="Orange"></Setter>
</DataTrigger>
</Style.Trigger>
This, however, does not work:
<TextBlock.Style>
Error message: The property "Style" can be set only once.
My reaction: So what? It is set only once.
<Setter Property="HorizontalAlignment" Value="Center"/>
Error message: Property "Style" does not support values of type "Setter".
My reaction: What are you talking about? I'm using the same thing as in the resources definition.
<Setter Property="FontWeight" Value="Bold"/>
Error message: The specified value cannot be assigned. The following type was exptected: "Style".
My reaction: ???
<Style.Trigger>
Error message: The attachable property "Trigger" was not found in type "Style".
My reaction: What are you talking about? There are triggers all over the xaml file.
Can anybody shed some light on this matter?