I don't think you can change the color of a resource from a trigger in xaml.
You can change the color in codebehind or set the color in SolidColorBrush for the database property of your object.
SolidColorBrush myBrush = (SolidColorBrush)this.TryFindResource("BlackBrush"); if (myBrush != null) { myBrush.Color = Colors.Yellow; }
Otherwise, you need to change the brushes based on the trigger. The following is an example:
<Grid Margin="50"> <Grid.Resources> <SolidColorBrush x:Key="BlackBrush" Color="Black"/> <SolidColorBrush x:Key="WhiteBrush" Color="White"/> <Style x:Key="test" TargetType="TextBlock"> <Setter Property="Background" Value="{StaticResource BlackBrush}"/> <Style.Triggers> <Trigger Property="Text" Value="white"> <Setter Property="Background" Value="{StaticResource WhiteBrush}"/> </Trigger> <Trigger Property="Text" Value="black"> <Setter Property="Background" Value="{StaticResource BlackBrush}"/> </Trigger> </Style.Triggers> </Style> </Grid.Resources> <TextBlock Height="20" Margin="50" Padding="50" Style="{StaticResource test}" Text="white"> </TextBlock> </Grid>
This will change the background color based on the text value; if the text is white, then the background is white, black, then the background is black.
source share