Skip to content

Commit 910d81d

Browse files
committed
Revert "Revert "Update MainWindow.axaml.cs""
This reverts commit 9a53262.
1 parent 9a53262 commit 910d81d

File tree

1 file changed

+18
-31
lines changed

1 file changed

+18
-31
lines changed

SFP_UI/Views/MainWindow.axaml.cs

+18-31
Original file line numberDiff line numberDiff line change
@@ -36,34 +36,36 @@ public MainWindow()
3636
}
3737
};
3838

39-
Application.Current!.ActualThemeVariantChanged += ApplicationActualThemeVariantChanged;
39+
Application.Current!.ActualThemeVariantChanged += OnActualThemeVariantChanged;
4040

4141
App.SetApplicationTheme(Settings.Default.AppTheme);
4242
}
4343

4444
public static MainWindow? Instance { get; private set; }
4545

46-
private void ApplicationActualThemeVariantChanged(object? sender, EventArgs e)
46+
private void OnActualThemeVariantChanged(object? sender, EventArgs e)
4747
{
48-
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
48+
if (!IsWindows11)
4949
{
5050
return;
5151
}
5252

53-
// TODO: add Windows version to CoreWindow
54-
if (IsWindows11 && ActualThemeVariant != FluentAvaloniaTheme.HighContrastTheme)
53+
if (ActualThemeVariant != FluentAvaloniaTheme.HighContrastTheme)
5554
{
5655
TryEnableMicaEffect();
5756
}
58-
else if (ActualThemeVariant != FluentAvaloniaTheme.HighContrastTheme)
57+
else
5958
{
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);
6261
}
6362
}
6463

6564
private void TryEnableMicaEffect()
6665
{
66+
TransparencyBackgroundFallback = Brushes.Transparent;
67+
TransparencyLevelHint = new[] { WindowTransparencyLevel.Mica, WindowTransparencyLevel.None };
68+
6769
// The background colors for the Mica brush are still based around SolidBackgroundFillColorBase resource
6870
// BUT since we can't control the actual Mica brush color, we have to use the window background to create
6971
// the same effect. However, we can't use SolidBackgroundFillColorBase directly since its opaque, and if
@@ -73,22 +75,18 @@ private void TryEnableMicaEffect()
7375
// CompositionBrush to properly change the color but I don't know if we can do that or not
7476
if (ActualThemeVariant == ThemeVariant.Dark)
7577
{
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);
8080

8181
color = color.LightenPercent(-0.8f);
8282

83-
Background = new ImmutableSolidColorBrush(color, 0.78);
83+
Background = new ImmutableSolidColorBrush(color, 0.9);
8484
}
8585
else if (ActualThemeVariant == ThemeVariant.Light)
8686
{
8787
// 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);
9290

9391
color = color.LightenPercent(0.5f);
9492

@@ -100,22 +98,11 @@ protected override void OnOpened(EventArgs e)
10098
{
10199
base.OnOpened(e);
102100

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)
111103
{
112-
return;
104+
TryEnableMicaEffect();
113105
}
114-
115-
TransparencyBackgroundFallback = Brushes.Transparent;
116-
TransparencyLevelHint = new[] { WindowTransparencyLevel.Mica, WindowTransparencyLevel.None };
117-
118-
TryEnableMicaEffect();
119106
}
120107

121108
protected override async void OnClosing(WindowClosingEventArgs e)

0 commit comments

Comments
 (0)