How to implement theming in wpf
Asked Answered
G

2

4

I want to implement ASP.Net type theme in WPF. User have selection of various predefined themes and can switch to another theme.

To implement this I have tried by creating different resourcedictionary for each theme and store required style with key. The collection of keys are same in all themes but its definition is different in each.

I am using below code to switch theme on click:

var theme = Application.LoadComponent(uri) as ResourceDictionary;
Application.Current.Resources.MergedDictionaries.Clear();
Application.Current.Resources.MergedDictionaries.Add(theme);

In all pages/ usercontrol/ windows I have set StaticResource and applied appropriate key. When I switch to another theme it is only applied after next event on UI.

If I set change StaticResource to DynamicResource then it is applied on immediately.

Please share your idea to achieve this with StaticResource?

Gare answered 22/6, 2012 at 5:21 Comment(0)
C
0

have a look at the question

WPF and MVVM - changing themes dynamically

you can download predefined themes from below link

http://wpf.codeplex.com/wikipage?title=WPF%20Themes

Castellated answered 22/6, 2012 at 6:18 Comment(1)
Thanks for your reply, but its not working with StaticResource.Gare
K
0

Unfortunately, you can't achieve this with StaticResource. The Control with the StaticResource needs to be reloaded after switching to another Theme for the new resource to be applied.

You might want to create functionality to reload the current page after change of theme.

Kristy answered 30/9, 2017 at 8:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.