microsoft-ui-xaml: UISettings.ColorValuesChanged not fired
Describe the bug
The UISettings.ColorValuesChanged event does not work for me.
Steps to reproduce the bug
- Create empty project
- In
MainWindow, add the following code:
public MainWindow()
{
InitializeComponent();
var settings = new UISettings();
settings.ColorValuesChanged += Settings_ColorValuesChanged;
}
private void Settings_ColorValuesChanged(UISettings sender, object args)
{
Debug.WriteLine("Theme changed");
}
- Change Windows colors, nothing will be printed in the output
Expected behavior
Theme changed printed in the output.
Screenshots
No response
NuGet package version
WinUI 3 - Windows App SDK 1.4.5: 1.4.240411001
Windows version
Windows 10 (21H2): Build 19044
Additional context
Actual Windows build: 19045.3930
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 16 (1 by maintainers)
For just the Theme , there is Microsoft.UI.Xaml.FrameworkElement.ActualThemeChanged It works for packaged/unpackaged (at least on Windows 10) :
I think the issue should be reopened because the provided solution seems temporary: I think that the official documented C# APIs should provide an event that notifies when the user change system colors. I don’t care if the name is
UISettings.ColorValuesChangedor whatever other class/event name, but this remains a basic feature for modern systems.For anyone that will have the same question, here’s how I did it in C# using the WinUIEx library:
MainWindow.xaml.csTitleBarHelperis the default helper generated with Template Studio for WinUI.I couldn’t replicate the C++ code fully, because there’s no string in the event args, so I don’t have anything to compare “ImmersiveColorSet” to, so I suspect the method is called more often than necessary.