From af6c52660d5f13a45482a88aea0fccec9156893e Mon Sep 17 00:00:00 2001 From: Zhang Dian <54255897+zdpcdt@users.noreply.github.com> Date: Mon, 6 Jan 2025 22:14:06 +0800 Subject: [PATCH] feat: sync high-contrast themes under the Windows OS. --- demo/Semi.Avalonia.Demo/App.axaml.cs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/demo/Semi.Avalonia.Demo/App.axaml.cs b/demo/Semi.Avalonia.Demo/App.axaml.cs index b4482be..1dccc74 100644 --- a/demo/Semi.Avalonia.Demo/App.axaml.cs +++ b/demo/Semi.Avalonia.Demo/App.axaml.cs @@ -1,7 +1,10 @@ +using System.Runtime.InteropServices; using Avalonia; using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Data.Core.Plugins; using Avalonia.Markup.Xaml; +using Avalonia.Media; +using Avalonia.Platform; using Semi.Avalonia.Demo.Views; namespace Semi.Avalonia.Demo; @@ -28,6 +31,30 @@ public partial class App : Application break; } + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + var setting = PlatformSettings?.GetColorValues(); + if (setting?.ContrastPreference is ColorContrastPreference.High) + { + if (setting.AccentColor1 == Color.Parse("#8EE3F0")) + { + RequestedThemeVariant = SemiTheme.Aquatic; + } + else if (setting.AccentColor1 == Color.Parse("#903909")) + { + RequestedThemeVariant = SemiTheme.Desert; + } + else if (setting.AccentColor1 == Color.Parse("#A1BFDE")) + { + RequestedThemeVariant = SemiTheme.Dusk; + } + else if (setting.AccentColor1 == Color.Parse("#D6B4FD")) + { + RequestedThemeVariant = SemiTheme.NightSky; + } + } + } + base.OnFrameworkInitializationCompleted(); } } \ No newline at end of file