Fix title bar not updating on system theme change #840
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
The app's title bar was not updating its colors when switching between dark and light mode in Windows system settings. This PR fixes the issue so the title bar correctly reflects the current system theme.
What
When changing the Windows system theme from dark to light (or vice versa), the app's title bar remained in the old theme colors while the rest of the app updated.
Root Cause
Two issues in
NewArch/windows/NewArch/NewArch.cpp:UISettingsobject going out of scope — TheuiSettingsvariable used to subscribe toColorValuesChangedwas a local variable inside thetryblock. Once the block finished executing, the object was destroyed, silently removing the event subscription. The theme change callback would never fire.Background thread callback —
ColorValuesChangedfires on a background thread, but updating the title bar requires running on the UI thread.How
UISettingsinstancestaticso it persists for the entire lifetime of the application, keeping theColorValuesChangedevent subscription alive.DispatcherQueuefor the UI thread and usedTryEnqueueinside the callback to marshal the title bar update back to the UI thread.Changes
NewArch/windows/NewArch/NewArch.cpp— Fixed title bar theme change listener lifetime and thread marshaling.Screenshot
Fixtheme.mp4
Testing
Microsoft Reviewers: Open in CodeFlow