11namespace ResXManager
22{
3+ using System . Collections . ObjectModel ;
4+ using System . ComponentModel ;
35 using System . Composition ;
6+ using System . Windows ;
7+ using System . Windows . Threading ;
8+
9+ using PropertyChanged ;
410
511 using ResXManager . Infrastructure ;
612 using ResXManager . Model ;
13+ using ResXManager . Properties ;
14+
15+ using TomsToolbox . Essentials ;
16+ using TomsToolbox . Wpf ;
17+
18+ public enum ColorTheme
19+ {
20+ [ LocalizedDisplayName ( StringResourceKey . ColorTheme_System ) ]
21+ System ,
22+
23+ [ LocalizedDisplayName ( StringResourceKey . ColorTheme_Light ) ]
24+ Light ,
25+
26+ [ LocalizedDisplayName ( StringResourceKey . ColorTheme_Dark ) ]
27+ Dark
28+ }
729
830 [ Export ( typeof ( IConfiguration ) ) ]
931 [ Export ( typeof ( Configuration ) ) ]
1032 [ Shared ]
1133 public class StandaloneConfiguration : Configuration
1234 {
35+ private readonly Collection < ResourceDictionary > _colorThemeResourceContainer ;
36+
1337 [ ImportingConstructor ]
1438 public StandaloneConfiguration ( ITracer tracer )
1539 : base ( tracer )
1640 {
41+ var themeDictionary = new ResourceDictionary ( ) ;
42+ var applicationDictionaries = Application . Current . Resources . MergedDictionaries ;
43+ applicationDictionaries . Insert ( 0 , themeDictionary ) ;
44+ _colorThemeResourceContainer = themeDictionary . MergedDictionaries ;
45+ Dispatcher . CurrentDispatcher . BeginInvoke ( DispatcherPriority . Normal , OnColorThemeChanged ) ;
1746 }
1847
1948 public override bool IsScopeSupported => false ;
2049
2150 public override ConfigurationScope Scope => ConfigurationScope . Global ;
51+
52+ [ DefaultValue ( nameof ( ColorTheme . Light ) ) ]
53+ [ OnChangedMethod ( nameof ( OnColorThemeChanged ) ) ]
54+ public ColorTheme ColorTheme { get ; set ; }
55+
56+ private void OnColorThemeChanged ( )
57+ {
58+ _colorThemeResourceContainer . Clear ( ) ;
59+
60+ switch ( ColorTheme )
61+ {
62+ case ColorTheme . System :
63+ break ;
64+ case ColorTheme . Light :
65+ _colorThemeResourceContainer . Add ( new ResourceDictionary { Source = GetType ( ) . Assembly . GeneratePackUri ( "Themes/LightTheme.xaml" ) } ) ;
66+ break ;
67+ case ColorTheme . Dark :
68+ _colorThemeResourceContainer . Add ( new ResourceDictionary { Source = GetType ( ) . Assembly . GeneratePackUri ( "Themes/DarkTheme.xaml" ) } ) ;
69+ break ;
70+ }
71+ }
2272 }
23- }
73+ }
0 commit comments