Skip to content

[Bug] SystemThemeWatcher not working in v4.2.0 #1656

@hluica

Description

@hluica

Describe the bug

In version v4.2.0, the system theme monitoring functionality appears to be broken. Specifically:

  1. SystemThemeWatcher.Watch(this) fails to respond to system theme changes while the application is running.
  2. The ApplicationThemeManager.Changed event 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ⭐ top bugTop bug.bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions