In WPF, you can associate the key in "{StaticResource key}" with a variable.
For instance. I have an ExecutionState variable with the states Active and Completed .
In my ResourceDictionary I have
<Style TargetType="{x:Type TextBlock}" x:Key="Active">
<Setter Property="Foreground" Value="Yellow"/>
</Style>
<Style TargetType="{x:Type TextBlock}" x:Key="Completed">
<Setter Property="Foreground" Value="Green"/>
</Style>
Instead
<TextBlock Style="{StaticResource Active}"/>
I would like to have something like
<TextBlock Style="{StaticResource {Binding ExecutionState}}"/>
Thus, if the state changes the color of the text. Is something like this possible? I can achieve the desired functionality with triggers, but I have to reuse it in several places, and I don't want to clutter up my code. I also use MVVM.
thank
source
share