microsoft / microsoft/microsoft-ui-xaml

Enumerating theme resources breaks theming

Open
#11,044 0 comments 0 reactions 0 assignees View on GitHub
area-Resources bug
Dominant language
C++
Stars
8.4k
Forks
942
Avg merge
2d 7h
Merged PRs (30d)
105

Description

### Describe the bug

When application's theme dictionaries are enumerated, dynamic theme changes stop working.

### Why is this important?

Enumerating should not have side-effects.

### Steps to reproduce the bug

1. Blank WinUI app
2. XAML:

```


Change theme
Enumerate

```

3. Code-behind

```csharp
private void ChangeTheme()
{
ParentGrid.RequestedTheme = ElementTheme.Dark;
}

private void EnumerateRDs()
{
foreach (var kvp in Application.Current.Resources.MergedDictionaries)
{
foreach (var th in kvp.ThemeDictionaries)
{
if (th.Value is ResourceDictionary r)
{
foreach (var key in r)
{
}
}
}
}
}
```

4. Have OS in light theme, run app and click Change theme button - notice the theme changes successfully and background changes to dark
5. Stop debugging
6. Start app again and click Enumerate button
7. **Click Change theme button and notice theme no longer changes and background stays light.**

### Actual behavior

`RequestedTheme` has no effect

### Expected behavior

Should work

### Screenshots

_No response_

### NuGet package version

1.8.260317003

### Windows version

Windows 11 (24H2): Build 26100

### Additional context

_No response_

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue in a blank WinUI app using the provided XAML and the ChangeTheme and EnumerateRDs handlers. Start by examining Application.Current.Resources.MergedDictionaries and its ThemeDictionaries during enumeration. Done means enumerating the resource dictionaries does not prevent a later RequestedTheme change from updating the background.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
desktop, frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.