11using System . Windows ;
22using System . Windows . Interop ;
3+ using System . Windows . Media ;
34using Wpf . Ui . Appearance ;
45using Wpf . Ui . Controls ;
56using Wpf . Ui . Mvvm . Contracts ;
@@ -18,18 +19,67 @@ public WpfUiWindow()
1819
1920 public void ApplyTheme ( )
2021 {
21- const int customThemeIndex = 2 ; // index for CustomTheme merged dictionary
22+ const int customThemeIndex = 2 ;
2223
23- _themeService . SetTheme ( App . Settings . Prop . Theme . GetFinal ( ) == Enums . Theme . Light ? ThemeType . Light : ThemeType . Dark ) ;
24+ var finalTheme = App . Settings . Prop . Theme . GetFinal ( ) ;
25+
26+ _themeService . SetTheme ( finalTheme == Enums . Theme . Light ? ThemeType . Light : ThemeType . Dark ) ;
2427 _themeService . SetSystemAccent ( ) ;
2528
26- // there doesn't seem to be a way to query the name for merged dictionaries
27- var dict = new ResourceDictionary { Source = new Uri ( $ "pack://application:,,,/UI/Style/{ Enum . GetName ( App . Settings . Prop . Theme . GetFinal ( ) ) } .xaml") } ;
28- Application . Current . Resources . MergedDictionaries [ customThemeIndex ] = dict ;
29+ if ( finalTheme == Enums . Theme . Custom )
30+ {
31+ Application . Current . Resources [ "WindowBackgroundGradient" ] = null ;
32+
33+ double angle = App . Settings . Prop . GradientAngle ;
34+ double angleRad = angle * Math . PI / 180.0 ;
35+
36+ double startX = 0.5 + 0.5 * Math . Cos ( angleRad + Math . PI ) ;
37+ double startY = 0.5 + 0.5 * Math . Sin ( angleRad + Math . PI ) ;
38+ double endX = 0.5 + 0.5 * Math . Cos ( angleRad ) ;
39+ double endY = 0.5 + 0.5 * Math . Sin ( angleRad ) ;
40+
41+ var customBrush = new LinearGradientBrush
42+ {
43+ StartPoint = new Point ( startX , startY ) ,
44+ EndPoint = new Point ( endX , endY )
45+ } ;
46+
47+ foreach ( var stop in App . Settings . Prop . CustomGradientStops . OrderBy ( s => s . Offset ) )
48+ {
49+ try
50+ {
51+ var color = ( Color ) ColorConverter . ConvertFromString ( stop . Color ) ;
52+ customBrush . GradientStops . Add ( new GradientStop ( color , stop . Offset ) ) ;
53+ }
54+ catch { }
55+ }
56+
57+ Application . Current . Resources [ "WindowBackgroundGradient" ] = customBrush ;
58+
59+ Application . Current . Resources [ "NewTextEditorBackground" ] = new SolidColorBrush ( ( Color ) ColorConverter . ConvertFromString ( "#59000000" ) ) ;
60+ Application . Current . Resources [ "NewTextEditorForeground" ] = new SolidColorBrush ( Colors . White ) ;
61+ Application . Current . Resources [ "NewTextEditorLink" ] = new SolidColorBrush ( ( Color ) ColorConverter . ConvertFromString ( "#3A9CEA" ) ) ;
62+ Application . Current . Resources [ "PrimaryBackgroundColor" ] = new SolidColorBrush ( ( Color ) ColorConverter . ConvertFromString ( "#19000000" ) ) ;
63+ Application . Current . Resources [ "NormalDarkAndLightBackground" ] = new SolidColorBrush ( ( Color ) ColorConverter . ConvertFromString ( "#0FFFFFFF" ) ) ;
64+ Application . Current . Resources [ "ControlFillColorDefault" ] = ( Color ) ColorConverter . ConvertFromString ( "#19000000" ) ;
65+ }
66+ else
67+ {
68+ var dict = new ResourceDictionary { Source = new Uri ( $ "pack://application:,,,/UI/Style/{ Enum . GetName ( finalTheme ) } .xaml") } ;
69+ Application . Current . Resources . MergedDictionaries [ customThemeIndex ] = dict ;
70+
71+ Application . Current . Resources [ "WindowBackgroundGradient" ] = null ;
72+ Application . Current . Resources . Remove ( "NewTextEditorBackground" ) ;
73+ Application . Current . Resources . Remove ( "NewTextEditorForeground" ) ;
74+ Application . Current . Resources . Remove ( "NewTextEditorLink" ) ;
75+ Application . Current . Resources . Remove ( "PrimaryBackgroundColor" ) ;
76+ Application . Current . Resources . Remove ( "NormalDarkAndLightBackground" ) ;
77+ Application . Current . Resources . Remove ( "ControlFillColorDefault" ) ;
78+ }
2979
3080#if QA_BUILD
31- this . BorderBrush = System . Windows . Media . Brushes . Red ;
32- this . BorderThickness = new Thickness ( 4 ) ;
81+ this . BorderBrush = System . Windows . Media . Brushes . Red ;
82+ this . BorderThickness = new Thickness ( 4 ) ;
3383#endif
3484 }
3585
0 commit comments