Click here to Skip to main content
15,038,451 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi.

In my WPF test project I tried to make the style dynamically changeable through a combobox. Everything works except the background color of the windows.



Can you help me?

The source code is here.
https://github.com/reddevlab/WpfCambioStile
Thank you!

What I have tried:

I have tried with StaticResource, with SolidColorBrush, with the same name, with different name of static resource but it does not work!
Posted
Updated 1-Jul-21 3:39am
Comments
CHill60 1-Jul-21 8:29am
   
I am unable to follow that link. Post the relevant code in your question - you can use the "Improve Question" link to add the information
Richard Deeming 1-Jul-21 8:52am
   
Try using DynamicResource instead:
Style="{DynamicResource BaseStyle}"

1 solution

Richard Deeming is correct, you've used the DynamicResource to allocate the styles to the elements, but the styles themselves are using StaticResource to allocate the colours. You need to amend the styles themselves to use dynamic resources:

C#
<Style x:Key="BaseStyle" TargetType="{x:Type Control}" >
    <Setter Property="Background" Value="{DynamicResource FormBackground}" />
</Style>

A StaticResource is resolved and assigned when the style is loaded, and any changes to that resource won't be reflected. The DynamicResource uses an expression to resolve the value, so changes can be reflected.
   
Comments
Red.Devlab 2-Jul-21 4:58am
   
Yesss!!! I have changed from Static to Dynamic and it's works! Thank you for your help!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900