@@ -82,13 +82,14 @@ public bool ChangeTheme(string theme)
82
82
{
83
83
if ( string . IsNullOrEmpty ( path ) )
84
84
throw new DirectoryNotFoundException ( "Theme path can't be found <{path}>" ) ;
85
-
86
- Settings . Theme = theme ;
87
-
85
+
88
86
// reload all resources even if the theme itself hasn't changed in order to pickup changes
89
87
// to things like fonts
90
- UpdateResourceDictionary ( GetResourceDictionary ( ) ) ;
88
+ UpdateResourceDictionary ( GetResourceDictionary ( theme ) ) ;
89
+
90
+ Settings . Theme = theme ;
91
91
92
+
92
93
//always allow re-loading default theme, in case of failure of switching to a new theme from default theme
93
94
if ( _oldTheme != theme || theme == defaultTheme )
94
95
{
@@ -134,9 +135,9 @@ private void UpdateResourceDictionary(ResourceDictionary dictionaryToUpdate)
134
135
_oldResource = dictionaryToUpdate ;
135
136
}
136
137
137
- private ResourceDictionary CurrentThemeResourceDictionary ( )
138
+ private ResourceDictionary GetThemeResourceDictionary ( string theme )
138
139
{
139
- var uri = GetThemePath ( Settings . Theme ) ;
140
+ var uri = GetThemePath ( theme ) ;
140
141
var dict = new ResourceDictionary
141
142
{
142
143
Source = new Uri ( uri , UriKind . Absolute )
@@ -145,10 +146,12 @@ private ResourceDictionary CurrentThemeResourceDictionary()
145
146
return dict ;
146
147
}
147
148
148
- public ResourceDictionary GetResourceDictionary ( )
149
+ private ResourceDictionary CurrentThemeResourceDictionary ( ) => GetThemeResourceDictionary ( Settings . Theme ) ;
150
+
151
+ public ResourceDictionary GetResourceDictionary ( string theme )
149
152
{
150
- var dict = CurrentThemeResourceDictionary ( ) ;
151
-
153
+ var dict = GetThemeResourceDictionary ( theme ) ;
154
+
152
155
if ( dict [ "QueryBoxStyle" ] is Style queryBoxStyle &&
153
156
dict [ "QuerySuggestionBoxStyle" ] is Style querySuggestionBoxStyle )
154
157
{
@@ -200,6 +203,11 @@ public ResourceDictionary GetResourceDictionary()
200
203
return dict ;
201
204
}
202
205
206
+ private ResourceDictionary GetCurrentResourceDictionary ( )
207
+ {
208
+ return GetResourceDictionary ( Settings . Theme ) ;
209
+ }
210
+
203
211
public List < string > LoadAvailableThemes ( )
204
212
{
205
213
List < string > themes = new List < string > ( ) ;
@@ -229,7 +237,7 @@ private string GetThemePath(string themeName)
229
237
230
238
public void AddDropShadowEffectToCurrentTheme ( )
231
239
{
232
- var dict = GetResourceDictionary ( ) ;
240
+ var dict = GetCurrentResourceDictionary ( ) ;
233
241
234
242
var windowBorderStyle = dict [ "WindowBorderStyle" ] as Style ;
235
243
@@ -273,7 +281,7 @@ public void AddDropShadowEffectToCurrentTheme()
273
281
274
282
public void RemoveDropShadowEffectFromCurrentTheme ( )
275
283
{
276
- var dict = CurrentThemeResourceDictionary ( ) ;
284
+ var dict = GetCurrentResourceDictionary ( ) ;
277
285
var windowBorderStyle = dict [ "WindowBorderStyle" ] as Style ;
278
286
279
287
var effectSetter = windowBorderStyle . Setters . FirstOrDefault ( setterBase => setterBase is Setter setter && setter . Property == Border . EffectProperty ) as Setter ;
0 commit comments