From 1d3f60a2a20b8a084b02b6e56f383a755def87c8 Mon Sep 17 00:00:00 2001 From: "Kai Tao (from Dev Box)" Date: Tue, 24 Feb 2026 21:04:28 +0800 Subject: [PATCH 1/3] fix oobe page theme color --- .../OOBE/Views/ScoobeReleaseNotesPage.xaml | 1 + .../OOBE/Views/ScoobeReleaseNotesPage.xaml.cs | 48 +++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/src/settings-ui/Settings.UI/SettingsXAML/OOBE/Views/ScoobeReleaseNotesPage.xaml b/src/settings-ui/Settings.UI/SettingsXAML/OOBE/Views/ScoobeReleaseNotesPage.xaml index b5e0abb4f691..4098841550bf 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/OOBE/Views/ScoobeReleaseNotesPage.xaml +++ b/src/settings-ui/Settings.UI/SettingsXAML/OOBE/Views/ScoobeReleaseNotesPage.xaml @@ -52,6 +52,7 @@ 0) + { + var (releaseNotesMarkdown, _) = ProcessReleaseNotesMarkdown(_currentReleases); + ReleaseNotesMarkdown.Text = releaseNotesMarkdown; + } + } + + /// + /// Updates MarkdownThemes header foreground brushes to match the current effective theme. + /// MarkdownThemes uses plain CLR properties initialized from Application.Current.Resources + /// at construction time, which resolves based on the app-level theme rather than the + /// window's RequestedTheme. This causes incorrect header colors when the two differ. + /// + private void ApplyMarkdownThemeColors() + { + if (Resources.TryGetValue("ReleaseNotesMarkdownThemeConfig", out var obj) && + obj is CommunityToolkit.WinUI.Controls.MarkdownThemes markdownThemes) + { + var foreground = ReleaseNotesMarkdown.Foreground; + markdownThemes.H1Foreground = foreground; + markdownThemes.H2Foreground = foreground; + markdownThemes.H3Foreground = foreground; + + // Resolve theme-aware brushes from the visual tree (respects RequestedTheme) + // rather than Application.Current.Resources (which uses the app-level theme). + var resources = ReleaseNotesMarkdown.XamlRoot?.Content switch + { + FrameworkElement fe => fe.Resources, + _ => Application.Current.Resources, + }; + + if (resources.TryGetValue("DividerStrokeColorDefaultBrush", out var dividerBrush) && + dividerBrush is Microsoft.UI.Xaml.Media.Brush brush) + { + markdownThemes.HorizontalRuleBrush = brush; + } + } + } + protected override void OnNavigatedTo(NavigationEventArgs e) { if (e.Parameter is IList releases) From d59071666ebc4edb2b7129cc7527c9417a5f7310 Mon Sep 17 00:00:00 2001 From: "Kai Tao (from Dev Box)" Date: Tue, 24 Feb 2026 21:49:42 +0800 Subject: [PATCH 2/3] fix --- .../OOBE/Views/ScoobeReleaseNotesPage.xaml.cs | 100 ++++++++++++------ 1 file changed, 65 insertions(+), 35 deletions(-) diff --git a/src/settings-ui/Settings.UI/SettingsXAML/OOBE/Views/ScoobeReleaseNotesPage.xaml.cs b/src/settings-ui/Settings.UI/SettingsXAML/OOBE/Views/ScoobeReleaseNotesPage.xaml.cs index 9629326186b6..ca8bd0e77df6 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/OOBE/Views/ScoobeReleaseNotesPage.xaml.cs +++ b/src/settings-ui/Settings.UI/SettingsXAML/OOBE/Views/ScoobeReleaseNotesPage.xaml.cs @@ -7,10 +7,13 @@ using System.Globalization; using System.Text; using System.Text.RegularExpressions; +using CommunityToolkit.WinUI.Controls; using ManagedCommon; using Microsoft.PowerToys.Settings.UI.Helpers; +using Microsoft.UI.Text; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Media; using Microsoft.UI.Xaml.Media.Imaging; using Microsoft.UI.Xaml.Navigation; @@ -19,6 +22,7 @@ namespace Microsoft.PowerToys.Settings.UI.OOBE.Views public sealed partial class ScoobeReleaseNotesPage : Page { private IList _currentReleases; + private string _currentMarkdown; /// /// Initializes a new instance of the class. @@ -26,6 +30,7 @@ public sealed partial class ScoobeReleaseNotesPage : Page public ScoobeReleaseNotesPage() { this.InitializeComponent(); + Unloaded += OnUnloaded; } /// @@ -127,10 +132,8 @@ private void DisplayReleaseNotes() { LoadingProgressRing.Visibility = Visibility.Collapsed; - // Apply correct theme-aware foreground colors before rendering - ApplyMarkdownThemeColors(); - var (releaseNotesMarkdown, heroImageUrl) = ProcessReleaseNotesMarkdown(_currentReleases); + _currentMarkdown = releaseNotesMarkdown; // Set the Hero image if found if (!string.IsNullOrEmpty(heroImageUrl)) @@ -143,7 +146,7 @@ private void DisplayReleaseNotes() HeroImageHolder.Visibility = Visibility.Collapsed; } - ReleaseNotesMarkdown.Text = releaseNotesMarkdown; + ApplyThemeAndRenderMarkdown(); ReleaseNotesMarkdown.Visibility = Visibility.Visible; } catch (Exception ex) @@ -155,51 +158,78 @@ private void DisplayReleaseNotes() private void Page_Loaded(object sender, RoutedEventArgs e) { ActualThemeChanged += OnActualThemeChanged; + App.ThemeService.ThemeChanged += OnAppThemeChanged; DisplayReleaseNotes(); } private void OnActualThemeChanged(FrameworkElement sender, object args) { - // Re-apply header foreground colors when theme changes at runtime - ApplyMarkdownThemeColors(); + ApplyThemeAndRenderMarkdown(); + } - if (_currentReleases != null && _currentReleases.Count > 0) + private void OnAppThemeChanged(object sender, ElementTheme theme) + { + if (DispatcherQueue.HasThreadAccess) { - var (releaseNotesMarkdown, _) = ProcessReleaseNotesMarkdown(_currentReleases); - ReleaseNotesMarkdown.Text = releaseNotesMarkdown; + ApplyThemeAndRenderMarkdown(); + return; } + + _ = DispatcherQueue.TryEnqueue(ApplyThemeAndRenderMarkdown); } - /// - /// Updates MarkdownThemes header foreground brushes to match the current effective theme. - /// MarkdownThemes uses plain CLR properties initialized from Application.Current.Resources - /// at construction time, which resolves based on the app-level theme rather than the - /// window's RequestedTheme. This causes incorrect header colors when the two differ. - /// - private void ApplyMarkdownThemeColors() + private void ApplyThemeAndRenderMarkdown() { - if (Resources.TryGetValue("ReleaseNotesMarkdownThemeConfig", out var obj) && - obj is CommunityToolkit.WinUI.Controls.MarkdownThemes markdownThemes) + var headingForeground = ReleaseNotesMarkdown.Foreground as Brush; + if (headingForeground == null) { - var foreground = ReleaseNotesMarkdown.Foreground; - markdownThemes.H1Foreground = foreground; - markdownThemes.H2Foreground = foreground; - markdownThemes.H3Foreground = foreground; - - // Resolve theme-aware brushes from the visual tree (respects RequestedTheme) - // rather than Application.Current.Resources (which uses the app-level theme). - var resources = ReleaseNotesMarkdown.XamlRoot?.Content switch - { - FrameworkElement fe => fe.Resources, - _ => Application.Current.Resources, - }; + return; + } - if (resources.TryGetValue("DividerStrokeColorDefaultBrush", out var dividerBrush) && - dividerBrush is Microsoft.UI.Xaml.Media.Brush brush) - { - markdownThemes.HorizontalRuleBrush = brush; - } + ReleaseNotesMarkdown.Config = BuildMarkdownConfig(headingForeground); + + if (string.IsNullOrEmpty(_currentMarkdown)) + { + return; } + + // Force markdown regeneration so headings pick up the updated theme config. + ReleaseNotesMarkdown.Text = string.Empty; + ReleaseNotesMarkdown.Text = _currentMarkdown; + } + + private static MarkdownConfig BuildMarkdownConfig(Brush headingForeground) + { + return new MarkdownConfig + { + Themes = new MarkdownThemes + { + BoldFontWeight = FontWeights.SemiBold, + H1FontSize = 28, + H1FontWeight = FontWeights.SemiBold, + H1Margin = new Thickness(0, 36, 0, 8), + H1Foreground = headingForeground, + H2FontSize = 20, + H2FontWeight = FontWeights.SemiBold, + H2Margin = new Thickness(0, 16, 0, 4), + H2Foreground = headingForeground, + H3FontSize = 16, + H3FontWeight = FontWeights.SemiBold, + H3Margin = new Thickness(0, 16, 0, 4), + H3Foreground = headingForeground, + HorizontalRuleThickness = 1, + ImageStretch = Stretch.Uniform, + ListBulletSpacing = 1, + ListGutterWidth = 10, + }, + }; + } + + private void OnUnloaded(object sender, RoutedEventArgs e) + { + ActualThemeChanged -= OnActualThemeChanged; + App.ThemeService.ThemeChanged -= OnAppThemeChanged; + Unloaded -= OnUnloaded; } protected override void OnNavigatedTo(NavigationEventArgs e) From 8e0287df11906399f25417c5e58afeaf923ec908 Mon Sep 17 00:00:00 2001 From: "Kai Tao (from Dev Box)" Date: Tue, 24 Feb 2026 22:13:55 +0800 Subject: [PATCH 3/3] centralize the style --- .../OOBE/Views/ScoobeReleaseNotesPage.xaml | 22 ------------------- 1 file changed, 22 deletions(-) diff --git a/src/settings-ui/Settings.UI/SettingsXAML/OOBE/Views/ScoobeReleaseNotesPage.xaml b/src/settings-ui/Settings.UI/SettingsXAML/OOBE/Views/ScoobeReleaseNotesPage.xaml index 4098841550bf..9c361ea7d647 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/OOBE/Views/ScoobeReleaseNotesPage.xaml +++ b/src/settings-ui/Settings.UI/SettingsXAML/OOBE/Views/ScoobeReleaseNotesPage.xaml @@ -7,27 +7,6 @@ xmlns:tkcontrols="using:CommunityToolkit.WinUI.Controls" Loaded="Page_Loaded" mc:Ignorable="d"> - - - - - @@ -51,7 +30,6 @@ Visibility="Visible" />