@@ -36,34 +36,36 @@ public MainWindow()
36
36
}
37
37
} ;
38
38
39
- Application . Current ! . ActualThemeVariantChanged += ApplicationActualThemeVariantChanged ;
39
+ Application . Current ! . ActualThemeVariantChanged += OnActualThemeVariantChanged ;
40
40
41
41
App . SetApplicationTheme ( Settings . Default . AppTheme ) ;
42
42
}
43
43
44
44
public static MainWindow ? Instance { get ; private set ; }
45
45
46
- private void ApplicationActualThemeVariantChanged ( object ? sender , EventArgs e )
46
+ private void OnActualThemeVariantChanged ( object ? sender , EventArgs e )
47
47
{
48
- if ( ! RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
48
+ if ( ! IsWindows11 )
49
49
{
50
50
return ;
51
51
}
52
52
53
- // TODO: add Windows version to CoreWindow
54
- if ( IsWindows11 && ActualThemeVariant != FluentAvaloniaTheme . HighContrastTheme )
53
+ if ( ActualThemeVariant != FluentAvaloniaTheme . HighContrastTheme )
55
54
{
56
55
TryEnableMicaEffect ( ) ;
57
56
}
58
- else if ( ActualThemeVariant != FluentAvaloniaTheme . HighContrastTheme )
57
+ else
59
58
{
60
- // Clear the local value here, and let the normal styles take over for HighContrast theme
61
- SetValue ( BackgroundProperty , AvaloniaProperty . UnsetValue ) ;
59
+ ClearValue ( BackgroundProperty ) ;
60
+ ClearValue ( TransparencyBackgroundFallbackProperty ) ;
62
61
}
63
62
}
64
63
65
64
private void TryEnableMicaEffect ( )
66
65
{
66
+ TransparencyBackgroundFallback = Brushes . Transparent ;
67
+ TransparencyLevelHint = new [ ] { WindowTransparencyLevel . Mica , WindowTransparencyLevel . None } ;
68
+
67
69
// The background colors for the Mica brush are still based around SolidBackgroundFillColorBase resource
68
70
// BUT since we can't control the actual Mica brush color, we have to use the window background to create
69
71
// the same effect. However, we can't use SolidBackgroundFillColorBase directly since its opaque, and if
@@ -73,22 +75,18 @@ private void TryEnableMicaEffect()
73
75
// CompositionBrush to properly change the color but I don't know if we can do that or not
74
76
if ( ActualThemeVariant == ThemeVariant . Dark )
75
77
{
76
- Color2 color = this . TryFindResource ( "SolidBackgroundFillColorBase" ,
77
- ThemeVariant . Dark , out var value )
78
- ? ( Color ) value !
79
- : new Color2 ( 32 , 32 , 32 ) ;
78
+ var color = this . TryFindResource ( "SolidBackgroundFillColorBase" ,
79
+ ThemeVariant . Dark , out var value ) ? ( Color2 ) ( Color ) value ! : new Color2 ( 32 , 32 , 32 ) ;
80
80
81
81
color = color . LightenPercent ( - 0.8f ) ;
82
82
83
- Background = new ImmutableSolidColorBrush ( color , 0.78 ) ;
83
+ Background = new ImmutableSolidColorBrush ( color , 0.9 ) ;
84
84
}
85
85
else if ( ActualThemeVariant == ThemeVariant . Light )
86
86
{
87
87
// Similar effect here
88
- Color2 color = this . TryFindResource ( "SolidBackgroundFillColorBase" ,
89
- ThemeVariant . Light , out var value )
90
- ? ( Color ) value !
91
- : new Color2 ( 243 , 243 , 243 ) ;
88
+ var color = this . TryFindResource ( "SolidBackgroundFillColorBase" ,
89
+ ThemeVariant . Light , out var value ) ? ( Color2 ) ( Color ) value ! : new Color2 ( 243 , 243 , 243 ) ;
92
90
93
91
color = color . LightenPercent ( 0.5f ) ;
94
92
@@ -100,22 +98,11 @@ protected override void OnOpened(EventArgs e)
100
98
{
101
99
base . OnOpened ( e ) ;
102
100
103
- // Enable Mica on Windows 11
104
- if ( ! RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
105
- {
106
- return ;
107
- }
108
-
109
- // TODO: add Windows version to CoreWindow
110
- if ( ! IsWindows11 || ActualThemeVariant == FluentAvaloniaTheme . HighContrastTheme )
101
+ var thm = ActualThemeVariant ;
102
+ if ( IsWindows11 && thm != FluentAvaloniaTheme . HighContrastTheme )
111
103
{
112
- return ;
104
+ TryEnableMicaEffect ( ) ;
113
105
}
114
-
115
- TransparencyBackgroundFallback = Brushes . Transparent ;
116
- TransparencyLevelHint = new [ ] { WindowTransparencyLevel . Mica , WindowTransparencyLevel . None } ;
117
-
118
- TryEnableMicaEffect ( ) ;
119
106
}
120
107
121
108
protected override async void OnClosing ( WindowClosingEventArgs e )
0 commit comments