From 38e4a64bb8b0150ee1883f329c5bbfc8de2582dd Mon Sep 17 00:00:00 2001 From: estrogen elf <87099578+BlossomiShymae@users.noreply.github.com> Date: Sat, 3 May 2025 19:19:59 -0500 Subject: [PATCH] Add Mica theme for Windows 11 and newer --- Needlework.Net/Program.cs | 6 +++++- .../Views/MainWindow/MainWindowView.axaml.cs | 17 +++++++++++++++ .../Pages/Endpoints/EndpointsTabView.axaml | 21 +++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/Needlework.Net/Program.cs b/Needlework.Net/Program.cs index 0a1cc67..af77628 100644 --- a/Needlework.Net/Program.cs +++ b/Needlework.Net/Program.cs @@ -36,7 +36,11 @@ class Program return AppBuilder.Configure(() => new App(BuildServices())) .UsePlatformDetect() .WithInterFont() - .LogToTrace(); + .LogToTrace() + .With(new Win32PlatformOptions + { + CompositionMode = [ Win32CompositionMode.WinUIComposition, Win32CompositionMode.DirectComposition ] + }); } private static IServiceProvider BuildServices() diff --git a/Needlework.Net/Views/MainWindow/MainWindowView.axaml.cs b/Needlework.Net/Views/MainWindow/MainWindowView.axaml.cs index ec6a532..3f9eef6 100644 --- a/Needlework.Net/Views/MainWindow/MainWindowView.axaml.cs +++ b/Needlework.Net/Views/MainWindow/MainWindowView.axaml.cs @@ -1,3 +1,6 @@ +using System; +using System.Runtime.InteropServices; +using Avalonia.Controls; using FluentAvalonia.UI.Windowing; namespace Needlework.Net.Views.MainWindow; @@ -9,5 +12,19 @@ public partial class MainWindowView : AppWindow InitializeComponent(); TitleBar.ExtendsContentIntoTitleBar = true; + TransparencyLevelHint = [WindowTransparencyLevel.Mica, WindowTransparencyLevel.None]; + + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + if (IsWindows11OrNewer()) + { + Background = null; + } + } + } + + private static bool IsWindows11OrNewer() + { + return Environment.OSVersion.Version.Major >= 10 && Environment.OSVersion.Version.Build >= 22000; } } \ No newline at end of file diff --git a/Needlework.Net/Views/Pages/Endpoints/EndpointsTabView.axaml b/Needlework.Net/Views/Pages/Endpoints/EndpointsTabView.axaml index 64441ea..2daa3bd 100644 --- a/Needlework.Net/Views/Pages/Endpoints/EndpointsTabView.axaml +++ b/Needlework.Net/Views/Pages/Endpoints/EndpointsTabView.axaml @@ -15,6 +15,27 @@ + + + + + + + + + +