Skip to content

UISettings.ColorValuesChanged and AccessibilitySettings.HighContrastChanged do not start system theme observation #25256

Open

Description

@MartinZikmund

Current behavior

Subscribing to UISettings.ColorValuesChanged (or AccessibilitySettings.HighContrastChanged) never starts system theme observation. Both are plain field-like events, so adding a handler doesn't call SystemThemeHelper.ObserveThemeChanges().

The event only fires today because Application.InitializationCompleted subscribes to SystemThemeHelper.SystemThemeChanged / HighContrastChanged, and those events have explicit add accessors that call ObserveThemeChanges(). Without an initialized Application (class libraries, tests, or any code running before app init), the OS-side observation is never started and the event never fires.

Expected behavior

Adding a ColorValuesChanged handler should be enough for it to be raised when the OS theme or high contrast settings change, like it is on WinUI (where UISettings doesn't depend on an app being initialized).

This expectation is based on the WinUI API contract, not on a native WinUI repro or the WinUI C++ sources.

How to reproduce it

Confirmed by code inspection on master (cc4854160), not at runtime (toggling the OS theme from a test isn't practical):

  1. UISettings.ColorValuesChanged is a plain event, with no add accessor: UISettings.cs#L58. The same applies to AccessibilitySettings.HighContrastChanged.
  2. It is only raised from SystemThemeHelper.NotifyHighContrastSettingsChanged() (SystemThemeHelper.cs#L302-L307) and from Application.cs#L468.
  3. The OS observation is started only by ObserveThemeChanges() (SystemThemeHelper.cs#L231), which is called from the add accessors of SystemThemeHelper.SystemThemeChanged / HighContrastChanged (#L170-L190). The only subscriber in the framework is Application.InitializationCompleted.

So, in code that runs without Application.InitializationCompleted:

var settings = new UISettings();
settings.ColorValuesChanged += (s, e) => Console.WriteLine("changed");
// Switch the OS between light and dark: the handler is never called.

Workaround

Make sure the app is initialized (this is always the case in a normal Uno app), or subscribe to something that goes through SystemThemeHelper first.

Works on UWP/WinUI

Yes (expected behavior).

Environment

Uno Platform master

NuGet package version(s)

master @ cc48541

Affected platforms

All heads (the code is shared in Uno.WinRT). Impact is low: in a real app Application always subscribes during init.

IDE version

N/A

Relevant plugins

No response

Anything else we need to know?

Suggested fix: use explicit add/remove accessors over a backing delegate for both events, with add calling SystemThemeHelper.ObserveThemeChanges() (it's idempotent), the same pattern SystemThemeHelper.SystemThemeChanged already uses. A runtime test can subscribe without an initialized app and assert the observation is started.

Activity

  1. added
    kind/bug
    good first issue
    triage/untriaged
    project/non-ui ⚙️
    platform/all
    difficulty/starter 🚀
    on Oct 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    difficulty/starter 🚀good first issuekind/bugplatform/allproject/non-ui ⚙️triage/untriaged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions