CommunityToolkit / CommunityToolkit/Windows

ThemeListener.ThemeChanged does not work in WinUI 3

Aperta
#555 9 commenti 2 reazioni 0 assegnatari Vedi su GitHub
bug components::helpers regression
Lingua principale
C#
Stelle
1.1k
Fork
166
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

## 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)

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia dall’implementazione di ThemeListener e dal commento correlato dell’issue che segnala che gli eventi sottostanti non sono supportati in WinUI 3. Riproduci il comportamento in un’app C# con WinAppSDK 1.0.0, quindi verifica che la modifica del tema di sistema attivi ThemeChanged e segnali l’ApplicationTheme corrente.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
csharp
Ambito
desktop
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.