Repository navigation
ThemeListener.ThemeChanged does not work in WinUI 3 #555
Description
Activity
I believe this is still a known issue as there's no corresponding API yet in the WinAppSDK for this, right @azchohfi?
Not sure how we should best mark things that we know aren't working yet...
Yes, these events are not supported:
https://docs.microsoft.com/en-us/windows/apps/desktop/modernize/desktop-to-uwp-supported-api#eventsI don't know for sure, but I believe it will be possible to track this when they add the EnvironmentVariableChangeTracker. It should be out on 1.1, but I'm not 100% sure.
Reacted by Michael Hawker@azchohfi @zateutsch this is another case similar to CommunityToolkit/WindowsCommunityToolkit#4356 where there's a missing API or an API that doesn't work in unpackaged. I'm not sure if there's system APIs that are in similar places and get annotated as such somehow? Is there any better attributes or practice we should be doing here to better indicate what's not going to work currently with WinUI 3/WASDK?
这是我的解决方案,可能有些笨拙。欢迎大佬献策。
Here is my solution, probably a little clumsy. Welcome the big guy to contribute.我使用visual studio 2022创建了一个新的空白应用,使用的是Windows app sdk 1.1.5,经过测试发现,当系统主题发生变化时,UISettings().ColorValuesChanged事件仍然能够被触发。在事件触发后,可以读取注册表 “计算机\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize”项的两个键值,其中“AppsUseLightTheme”对应的是“默认应用模式”的设置,“SystemUsesLightTheme”对应的是“默认Windows模式“的设置。
I created a new blank app using Visual Studio 2022 using Windows app SDK 1.1.5 and tested UISettings() when the system theme changes. The ColorValuesChanged event can still be triggered. After the event triggered, you can read the two keys of the registry "Computer\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize" item, where "AppsUseLightTheme" corresponds to the setting of "Default App Mode", "SystemUsesLightTheme" Corresponding to the setting of "Default Windows Mode".AppsUseLightTheme 值为0时,是深色主题,1时是浅色主题。
AppsUseLightTheme is a dark theme when the value is 0 and light theme is at 1.这是我测试的代码。
Here is the code I tested.MainWindow.xaml
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" Orientation="Horizontal"> <Button x:Name="myButton" Content="{x:Bind TestString, Mode=OneWay}" /> </StackPanel>MainWindow.xaml.cs
using System;
using System.ComponentModel;
using Microsoft.UI.Dispatching;
using Microsoft.UI.Xaml;
using Microsoft.Win32;
using Windows.UI.ViewManagement;// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.namespace App1;
///
/// An empty window that can be used on its own or navigated to within a Frame.
///
public sealed partial class MainWindow : Window, INotifyPropertyChanged
{
private string testString = string.Empty;private DispatcherQueue dispatcherQueue = DispatcherQueue.GetForCurrentThread(); public string TestString { get => testString; set { testString = value; if (PropertyChanged != null) { PropertyChanged.Invoke(this, new PropertyChangedEventArgs(nameof(TestString))); } } } public MainWindow() { this.InitializeComponent(); UISettings uISettings = new UISettings(); uISettings.ColorValuesChanged += UISettings_ColorValuesChanged; } private void myButton_Click(object sender, RoutedEventArgs e) { } private void UISettings_ColorValuesChanged(UISettings sender, object args) { int value = GetRegistryValue(@"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize", "AppsUseLightTheme"); dispatcherQueue.TryEnqueue(() => { TestString = "当前主题是" + Convert.ToString(value); }); } private static int GetRegistryValue(string path, string paramName) { RegistryKey root = Registry.CurrentUser; RegistryKey rk = root.OpenSubKey(path); return Convert.ToInt32(rk.GetValue(paramName, null)); } public event PropertyChangedEventHandler PropertyChanged;}
It seems like
UISettings.ColorValueChangedis not called on Windows 10 (at least for 19045) with Winui3 1.4.2. Repro hereAny word on when this might be fixed, or if there's a known viable workaround?
Any word on when this might be fixed, or if there's a known viable workaround?
There is, but somehow still not getting reviewed
Reacted by Bart- addedbugSomething isn't workingSomething isn't workingregressionWhat was working is now brokeWhat was working is now broke
on Nov 13, 2024 Any word on when this might be fixed, or if there's a known viable workaround?
There is, but somehow still not getting reviewed
I've triaged and bumped the participants, hope to see movement again soon! 🤞
- addedcomponents::helpersHelpers for Colors, Network, Camera, WeakEventListener, PackageVersion, ScreenUnit and more.Helpers for Colors, Network, Camera, WeakEventListener, PackageVersion, ScreenUnit and more.
on Aug 7, 2025
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fields🏗 In progress


Describe the bug
ThemeListenerseems to do nothing in WinAppSDK apps. A comment in a related issue points out that the eventsThemeListenerrelies on are no longer supported in WinUI 3.7.1.2 for UWP
Steps to Reproduce
Steps to reproduce the behavior:
Place the following code anywhere inside a WinAppSDK 1.0.0 C# app:
Observe that the
ThemeChangedhandler is never fired.Expected behavior
The
ThemeChangedevent should fire when the system theme is changed.Environment
NuGet Package(s): CommunityToolkit.WinUI.UI
Package Version(s): 7.1.2
Windows 10 Build Number:
App min and target version:
Device form factor:
Visual Studio version: