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?
1 answer
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:
- Put the values of all visual properties into styles.
- Gather styles in
ResourceDictionary(let's call itskin1.xaml) - Connect all styles from
skin1.xamlviaDynamicResource. - Develop alternative styles, give them the same names, and put them in the next
ResourceDictionary(let's call itskin2.xaml) - At the beginning of the application, determine whether you want to work with skin1 or skin2
- Load in App.xaml in
Resourcesskin1.xamlorskin2.xamlinMergedDictionaries. - If you want to change colors during the program’s run, add another
ResourceDictionarytoMergedDictionaries, then remove the old one.
|
DynamicResource. - VladD