There is a WPF application made in a certain visual style, for example, the background of all windows and pages is gray. Is it possible, and if it is possible, how to most effectively change this background on all windows at once, even if page or window objects have not yet been created?

  • Variable? O.O. - Mike Waters
  • 2
    If all colors are set via styles, yes. Or, say, through DynamicResource . - VladD
  • You probably mean the topic? - user227049
  • @VladD thought about it. But how to change the style through the code? It is desirable to save the next time you start it. so you need to store colors not in style but in a separate file? - Sergey
  • @FoggyFinder as themes do you understand .NET objects? - Sergey

1 answer 1

What you want is called application styling . It does not work out just like that, you have to work.

The sequence of actions may be as follows:

  1. Put the values ​​of all visual properties into styles.
  2. Gather styles in ResourceDictionary (let's call it skin1.xaml )
  3. Connect all styles from skin1.xaml via DynamicResource .
  4. Develop alternative styles, give them the same names, and put them in the next ResourceDictionary (let's call it skin2.xaml )
  5. At the beginning of the application, determine whether you want to work with skin1 or skin2
  6. Load in App.xaml in Resources skin1.xaml or skin2.xaml in MergedDictionaries .
  7. If you want to change colors during the program’s run, add another ResourceDictionary to MergedDictionaries , then remove the old one.