[Bug] SystemThemeWatcher not working in v4.2.0
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 9.6k
- Forks
- 1k
- PR merge metrics
- No merged PRs in 30d
Description
Describe the bug
In version v4.2.0, the system theme monitoring functionality appears to be broken. Specifically:
SystemThemeWatcher.Watch(this)fails to respond to system theme changes while the application is running.- The
ApplicationThemeManager.Changedevent handler is not triggered when the system theme changes.
However, the initial theme detection at application startup still works correctly (the app loads with the correct current system theme). The issue is strictly related to dynamic updates at runtime.
I believe the root cause of the issue lies in the SystemThemeWatcher.Watch(this) method. When using this statement alone, the application fails to automatically update its theme in response to system changes.
This issue was not present in v4.1.0.
To Reproduce
This issue can be reproduced easily using a blank WPF project with the following configuration:
WpfApp1.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net10.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UseWPF>true</UseWPF>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="WPF-UI" Version="4.2.0" />
</ItemGroup>
</Project>
App.xaml
<Application
x:Class="WpfApp1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ui:ThemesDictionary />
<ui:ControlsDictionary />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
MainWindow.xaml
<ui:FluentWindow
x:Class="WpfApp1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
Title="MainWindow"
Width="800"
Height="450"
ExtendsContentIntoTitleBar="True"
WindowBackdropType="Mica">
<Grid>
<ui:TitleBar Title="Title" />
</Grid>
</ui:FluentWindow>
MainWindow.xaml.cs
using Wpf.Ui.Appearance;
using Wpf.Ui.Controls;
namespace WpfApp1;
public partial class MainWindow : FluentWindow
{
public MainWindow()
{
InitializeComponent();
// This should watch for changes, but it doesn't respond in v4.2.0
SystemThemeWatcher.Watch(this);
// This event also doesn't fire when system theme changes
ApplicationThemeManager.Changed += (theme, accent) =>
{
System.Diagnostics.Debug.WriteLine($"Theme changed to: {theme}");
};
}
}
Expected behavior
The application should automatically switch between Light/Dark themes when the Windows system theme is toggled in the OS settings.
Screenshots
No response
OS version
Windows 11 25H2, Build22620.7653 (Insider Dev Channel)
.NET version
SDK Version: 10.0.102
Host Version: 10.0.2
MSBuild version: 18.0.7+445250245
WPF-UI NuGet version
4.2.0
Additional context
Visual Studio Version: VS 2026, v18.2.1, stable.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the SystemThemeWatcher.Watch(this) call and ApplicationThemeManager.Changed handler shown in MainWindow.xaml.cs. Run the supplied blank WPF project on Windows, then trace the watcher behavior and compare it with v4.1.0. Done means runtime system-theme changes trigger the event and update the application theme in v4.2.0.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- desktop
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100