Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

DynamicResource not working with Color and SolidColorBrush

$
0
0

Hello everyone,

I have a problem with DynamicResource in my Resource Dictionary.
I have the following Code in the App.xaml:

<Color x:Key="Color1" >White</Color><Color x:Key="Color2" >Black</Color><Color x:Key="Color3" >Black</Color><SolidColorBrush x:Key="Brush1" Color="{DynamicResource ResourceKey=Color3}" /><SolidColorBrush x:Key="Brush2" Color="{DynamicResource ResourceKey=Color1}" /><SolidColorBrush x:Key="Brush3" Color="{DynamicResource ResourceKey=Color1}" /><Style TargetType="{x:Type Button}" ><Setter Property="Background" Value="{DynamicResource ResourceKey=Brush2}" /><Setter Property="BorderBrush" Value="{DynamicResource ResourceKey=Brush1}" /><Setter Property="Foreground" Value="{DynamicResource ResourceKey=Brush1}" /></Style>

And on my MainWindow I have a button with the following Click-Event:

App.Current.Resources["Color1"] = Colors.Red;

Now if I press the button the background color of the button should change to red. The problem is, that it does not.
This is and example. I actually have a really big Resource Dictionary with some base colors and Brushes that depends on this colors.

If there is no solution. Can I update the DynamicResource manually programmatically?

Note: If I change the Brushes programmatically it works fine


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>