using System; using System.Runtime.InteropServices; using System.Windows; using System.Windows.Interop; public static class Win11ThemeHelper { public static void ApplyDarkTitleBar(Window window) { var handle = new WindowInteropHelper(window).EnsureHandle(); var attribute = 20; // DWMWA_USE_IMMERSIVE_DARK_MODE bool useDarkMode = IsSystemDarkMode(); DwmSetWindowAttribute(handle, attribute, ref useDarkMode, Marshal.SizeOf(useDarkMode)); }
private static bool IsSystemDarkMode() { try { using var key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize"); return key?.GetValue("AppsUseLightTheme") is int val && val == 0; } catch { return false; } } } MainWindow.xaml windows desktop runtime 8.0 11
It sounds like you want to develop a feature for an app that runs on using .NET 8.0 (the runtime version) and is intended for Windows 11 (or Windows 10/11 with modern APIs). using System; using System