CommunityToolkit / CommunityToolkit/Windows
ThemeListener.ThemeChanged does not work in WinUI 3
- Dominant language
- C#
- Stars
- 1.1k
- Forks
- 166
- PR merge metrics
- No merged PRs in 30d
Description
## Describe the bug
`ThemeListener` seems to do nothing in WinAppSDK apps. [A comment in a related issue](https://github.com/CommunityToolkit/WindowsCommunityToolkit/issues/3656#issuecomment-810063280) points out that the events `ThemeListener` relies on are no longer supported in WinUI 3.
- [x] Is this bug a regression in the toolkit? If so, what toolkit version did you last see it work:
7.1.2 for UWP
## Steps to Reproduce
- [x] Can this be reproduced in the Sample App? (Either in a sample as-is or with new XAML pasted in the editor.) If so, please provide custom XAML or steps to reproduce. If not, let us know why it can't be reproduced (e.g. more complex setup, environment, dependencies, etc...)
Steps to reproduce the behavior:
Place the following code anywhere inside a WinAppSDK 1.0.0 C# app:
```cs
private void ThemeChanged(ThemeListener sender)
{
ApplicationTheme theme = sender.CurrentTheme;
Debug.WriteLine(theme);
}
ThemeListener themeListener = new();
themeListener.ThemeChanged += ThemeChanged;
```
Observe that the `ThemeChanged` handler is never fired.
## Expected behavior
The `ThemeChanged` event should fire when the system theme is changed.
## Environment
NuGet Package(s): CommunityToolkit.WinUI.UI
Package Version(s): 7.1.2
Windows 10 Build Number:
- [ ] Fall Creators Update (16299)
- [ ] April 2018 Update (17134)
- [ ] October 2018 Update (17763)
- [ ] May 2019 Update (18362)
- [ ] May 2020 Update (19041)
- [x] Insider Build (22504.1010)
App min and target version:
- [ ] Fall Creators Update (16299)
- [ ] April 2018 Update (17134)
- [ ] October 2018 Update (17763)
- [ ] May 2019 Update (18362)
- [ ] May 2020 Update (19041)
- [x] Insider Build (22000)
Device form factor:
- [x] Desktop
- [ ] Xbox
- [ ] Surface Hub
- [ ] IoT
Visual Studio version:
- [ ] 2017 (15.{minor_version})
- [ ] 2019 (16.{minor_version})
- [x] 2022 (17.0.2)
Contributor guide
Assessment
This issue has not been assessed yet.