I have in my application resources file brush:
<SolidColorBrush x:Key="MainColor" Color="#FF15428B" />
I want to change color of this brush at runtime. I added color picker - when user choose color I want this brush to have selected color.
I tried code like that:
SolidColorBrush MainColor = new SolidColorBrush(SelectedColor);
But it didn't work.
You need to set the existing brush's Color
property.
You can get the instance by writing (SolidColorBrush)Resources["MainColor"]
You can access Resources from the code-behind with the TryFindResource method:
SolidColorBrush myBrush = (SolidColorBrush)this.TryFindResource("myBrush");
if (myBrush != null)
{
myBrush.Color = Colors.Yellow ;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With