11using System ;
22using System . Collections . Generic ;
3+ using System . Linq ;
34using System . Windows ;
45using System . Windows . Media ;
56using HandyControl . Data ;
@@ -204,24 +205,18 @@ public virtual ResourceDictionary GetSkin(SkinType skinType)
204205 return _precSkin ;
205206 }
206207
207- private void UpdateAccentColor ( Color color )
208+ public static Theme GetTheme ( string name , ResourceDictionary resourceDictionary )
208209 {
209- _precSkin [ ResourceToken . PrimaryColor ] = color ;
210- _precSkin [ ResourceToken . DarkPrimaryColor ] = color ;
211- _precSkin [ ResourceToken . TitleColor ] = color ;
212- _precSkin [ ResourceToken . SecondaryTitleColor ] = color ;
213- }
214-
215- private void UpdateSkin ( ) => MergedDictionaries [ 0 ] = GetSkin ( Skin ) ;
216-
217- private ResourceDictionary _theme ;
210+ if ( string . IsNullOrEmpty ( name ) || resourceDictionary == null )
211+ {
212+ return null ;
213+ }
218214
219- public virtual ResourceDictionary GetTheme ( )
220- {
221- _theme ??= ResourceHelper . GetTheme ( ) ;
222- return _theme ;
215+ return resourceDictionary . MergedDictionaries . OfType < Theme > ( ) . FirstOrDefault ( item => Equals ( item . Name , name ) ) ;
223216 }
224217
218+ public virtual ResourceDictionary GetTheme ( ) => ResourceHelper . GetTheme ( ) ;
219+
225220 private void InitResource ( )
226221 {
227222 if ( DesignerHelper . IsInDesignMode )
@@ -233,10 +228,20 @@ private void InitResource()
233228 MergedDictionaries . Add ( GetSkin ( Skin ) ) ;
234229 MergedDictionaries . Add ( GetTheme ( ) ) ;
235230 }
231+
232+ private void UpdateAccentColor ( Color color )
233+ {
234+ _precSkin [ ResourceToken . PrimaryColor ] = color ;
235+ _precSkin [ ResourceToken . DarkPrimaryColor ] = color ;
236+ _precSkin [ ResourceToken . TitleColor ] = color ;
237+ _precSkin [ ResourceToken . SecondaryTitleColor ] = color ;
238+ }
239+
240+ private void UpdateSkin ( ) => MergedDictionaries [ 0 ] = GetSkin ( Skin ) ;
236241 }
237242
238243 public class StandaloneTheme : Theme
239244 {
240- public override ResourceDictionary GetTheme ( ) => ResourceHelper . GetTheme ( ) ;
245+ public override ResourceDictionary GetTheme ( ) => ResourceHelper . GetStandaloneTheme ( ) ;
241246 }
242247}
0 commit comments