From 487a071aba79d53707c643533b004799a218e092 Mon Sep 17 00:00:00 2001 From: hmishra Date: Thu, 25 Jul 2024 16:04:04 +0530 Subject: [PATCH 1/7] Sync Window Theme Mode with resources on resource update --- .../System/Windows/ThemeManager.cs | 41 +++++++++++++++++++ .../System/Windows/TreeWalkHelper.cs | 6 +++ 2 files changed, 47 insertions(+) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/ThemeManager.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/ThemeManager.cs index 282164e5af4..782073d2f66 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/ThemeManager.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/ThemeManager.cs @@ -1,6 +1,7 @@ using Standard; using Microsoft.Win32; using System.Collections; +using System.Collections.ObjectModel; using System.Collections.Generic; using System.Windows.Interop; using System.Windows.Media; @@ -178,6 +179,40 @@ internal static void SyncDeferredThemeModeAndResources() } } + internal static void SyncWindowThemeModeAndResources(Window window) + { + Collection windowResources = window.Resources.MergedDictionaries; + bool containsFluentResource = false; + + for (int i = windowResources.Count - 1 ; i >= 0 ; i--) + { + if (windowResources[i].Source.ToString().Contains("Fluent")) + { + containsFluentResource = true; + + if(windowResources[i].Source.ToString().Contains("Light")) + { + window.ThemeMode = ThemeMode.Light; + } + else if(windowResources[i].Source.ToString().Contains("Dark")) + { + window.ThemeMode = ThemeMode.Dark; + } + else + { + window.ThemeMode = ThemeMode.System; + } + + break; + } + } + + if(!containsFluentResource) + { + window.ThemeMode = ThemeMode.None; + } + } + internal static void ApplyStyleOnWindow(Window window) { if(!IsFluentThemeEnabled && window.ThemeMode == ThemeMode.None) return; @@ -326,6 +361,8 @@ internal static bool IsFluentThemeEnabled internal static bool IgnoreAppResourcesChange { get; set; } = false; + internal static bool IgnoreWindowResourcesChange { get; set; } = false; + internal static double DefaultFluentThemeFontSize => 14; internal static WindowCollection FluentEnabledWindows { get; set; } = new WindowCollection(); @@ -400,6 +437,8 @@ private static void AddOrUpdateThemeResources(ResourceDictionary rd, Uri diction var newDictionary = new ResourceDictionary() { Source = dictionaryUri }; int index = FindLastFluentThemeResourceDictionaryIndex(rd); + IgnoreWindowResourcesChange = true; + if (index >= 0) { rd.MergedDictionaries[index] = newDictionary; @@ -408,6 +447,8 @@ private static void AddOrUpdateThemeResources(ResourceDictionary rd, Uri diction { rd.MergedDictionaries.Insert(0, newDictionary); } + + IgnoreWindowResourcesChange = false; } private static int FindLastFluentThemeResourceDictionaryIndex(ResourceDictionary rd) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TreeWalkHelper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TreeWalkHelper.cs index 1489ff80f3b..9179ba13ff0 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TreeWalkHelper.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TreeWalkHelper.cs @@ -457,6 +457,12 @@ internal static void InvalidateOnResourcesChange( { Debug.Assert(fe != null || fce != null, "Node with the resources change notification must be an FE or an FCE."); + Window currentWindow = fe as Window; + if(currentWindow != null && !ThemeManager.IgnoreWindowResourcesChange) + { + ThemeManager.SyncWindowThemeModeAndResources(currentWindow); + } + // We're interested in changes to the Template property that occur during // the walk - if the template has changed we don't need to invalidate // template-driven properties a second time. The HasTemplateChanged property From eb8921b87b1e43029fa5693071a4bf1b67ec4285 Mon Sep 17 00:00:00 2001 From: hmishra Date: Fri, 26 Jul 2024 17:13:51 +0530 Subject: [PATCH 2/7] Code Refactoring and reusing implemented methods --- .../System/Windows/ThemeManager.cs | 40 ++++++++----------- .../System/Windows/TreeWalkHelper.cs | 5 ++- 2 files changed, 19 insertions(+), 26 deletions(-) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/ThemeManager.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/ThemeManager.cs index 782073d2f66..31787e3e257 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/ThemeManager.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/ThemeManager.cs @@ -181,35 +181,27 @@ internal static void SyncDeferredThemeModeAndResources() internal static void SyncWindowThemeModeAndResources(Window window) { - Collection windowResources = window.Resources.MergedDictionaries; - bool containsFluentResource = false; + ResourceDictionary windowResources = window.Resources; + int index = FindLastFluentThemeResourceDictionaryIndex(windowResources); - for (int i = windowResources.Count - 1 ; i >= 0 ; i--) + if ( index == -1 ) { - if (windowResources[i].Source.ToString().Contains("Fluent")) - { - containsFluentResource = true; - - if(windowResources[i].Source.ToString().Contains("Light")) - { - window.ThemeMode = ThemeMode.Light; - } - else if(windowResources[i].Source.ToString().Contains("Dark")) - { - window.ThemeMode = ThemeMode.Dark; - } - else - { - window.ThemeMode = ThemeMode.System; - } - - break; - } + window.ThemeMode = ThemeMode.None; + return; } - if(!containsFluentResource) + // Check: Do we need a null check here for source's value? + if (windowResources.MergedDictionaries[index].Source.ToString().ToLower().Contains("light")) { - window.ThemeMode = ThemeMode.None; + window.ThemeMode = ThemeMode.Light; + } + else if (windowResources.MergedDictionaries[index].Source.ToString().ToLower().Contains("dark")) + { + window.ThemeMode = ThemeMode.Dark; + } + else + { + window.ThemeMode = ThemeMode.System; } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TreeWalkHelper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TreeWalkHelper.cs index 9179ba13ff0..2f3642a4bc2 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TreeWalkHelper.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TreeWalkHelper.cs @@ -457,8 +457,9 @@ internal static void InvalidateOnResourcesChange( { Debug.Assert(fe != null || fce != null, "Node with the resources change notification must be an FE or an FCE."); - Window currentWindow = fe as Window; - if(currentWindow != null && !ThemeManager.IgnoreWindowResourcesChange) + // Here we are syncing the window's Theme mode when resource dictionary changes. + // The IgnoreWindowResourcesChange is a flag set to make sure the ThemeMode change does not cause an infinite loop of resource changes. + if(fe is Window currentWindow && !ThemeManager.IgnoreWindowResourcesChange) { ThemeManager.SyncWindowThemeModeAndResources(currentWindow); } From da17180d75a6c3bc481cf7d724caefa68cbe643f Mon Sep 17 00:00:00 2001 From: hmishra Date: Fri, 26 Jul 2024 18:53:58 +0530 Subject: [PATCH 3/7] Code clean-up --- .../System/Windows/Application.cs | 2 +- .../System/Windows/ThemeManager.cs | 27 +++++-------------- .../System/Windows/TreeWalkHelper.cs | 2 +- 3 files changed, 8 insertions(+), 23 deletions(-) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Application.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Application.cs index fb73e6ed105..8252981214d 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Application.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Application.cs @@ -1736,7 +1736,7 @@ internal void InvalidateResourceReferences(ResourcesChangeInfo info) if(!ThemeManager.IgnoreAppResourcesChange) { - if(ThemeManager.SyncThemeModeAndResources()) + if(ThemeManager.SyncApplicationThemeModeAndResources()) { return; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/ThemeManager.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/ThemeManager.cs index 31787e3e257..a70940d98de 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/ThemeManager.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/ThemeManager.cs @@ -127,17 +127,18 @@ internal static void OnWindowThemeChanged(Window window, ThemeMode oldThemeMode, ApplyFluentOnWindow(window); } - internal static bool SyncThemeModeAndResources() + internal static bool SyncApplicationThemeModeAndResources() { if(DeferSyncingThemeModeAndResources) return true; - ThemeMode themeMode = GetThemeModeFromResourceDictionary(Application.Current.Resources); + ThemeMode themeMode = GetThemeModeFromResourceDictionary(Application.Current.Resources); if(Application.Current.ThemeMode != themeMode) { Application.Current.ThemeMode = themeMode; return themeMode == ThemeMode.None ? false : true; } + return false; } @@ -181,27 +182,11 @@ internal static void SyncDeferredThemeModeAndResources() internal static void SyncWindowThemeModeAndResources(Window window) { - ResourceDictionary windowResources = window.Resources; - int index = FindLastFluentThemeResourceDictionaryIndex(windowResources); - - if ( index == -1 ) - { - window.ThemeMode = ThemeMode.None; - return; - } + ThemeMode themeMode = GetThemeModeFromResourceDictionary(window.Resources); - // Check: Do we need a null check here for source's value? - if (windowResources.MergedDictionaries[index].Source.ToString().ToLower().Contains("light")) - { - window.ThemeMode = ThemeMode.Light; - } - else if (windowResources.MergedDictionaries[index].Source.ToString().ToLower().Contains("dark")) - { - window.ThemeMode = ThemeMode.Dark; - } - else + if(window.ThemeMode != themeMode) { - window.ThemeMode = ThemeMode.System; + window.ThemeMode = themeMode; } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TreeWalkHelper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TreeWalkHelper.cs index 2f3642a4bc2..7d3dded9a88 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TreeWalkHelper.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TreeWalkHelper.cs @@ -457,7 +457,7 @@ internal static void InvalidateOnResourcesChange( { Debug.Assert(fe != null || fce != null, "Node with the resources change notification must be an FE or an FCE."); - // Here we are syncing the window's Theme mode when resource dictionary changes. + // Here we are syncing the window's Theme mode if resource dictionary changes. // The IgnoreWindowResourcesChange is a flag set to make sure the ThemeMode change does not cause an infinite loop of resource changes. if(fe is Window currentWindow && !ThemeManager.IgnoreWindowResourcesChange) { From 704d3ea364caad71995f589ef98055c2bcbea3ac Mon Sep 17 00:00:00 2001 From: Harshit <62823486+harshit7962@users.noreply.github.com> Date: Wed, 14 Aug 2024 11:19:49 +0530 Subject: [PATCH 4/7] Fix StaticResource usage for Fluent Theme (#50) * Fix (Fluent): Usage of defined resources as StaticResources * Fix(Fluent): Usage of static resource at window level * Updating access modifier * Code Cleanup * Renaming property and field --- .../System/Windows/FrameworkElement.cs | 9 +++- .../System/Windows/TreeWalkHelper.cs | 8 ++- .../System/Windows/Window.cs | 54 ++++++++++++++++++- 3 files changed, 67 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkElement.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkElement.cs index c85e2c70d73..b5157daf65e 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkElement.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkElement.cs @@ -707,6 +707,8 @@ public ResourceDictionary Resources } set { + bool invalidateResources = false; + ResourceDictionary oldValue = ResourcesField.GetValue(this); ResourcesField.SetValue(this, value); @@ -727,6 +729,11 @@ public ResourceDictionary Resources oldValue.RemoveOwner(this); } + if(this is Window window) + { + window.AddFluentDictionary(value, out invalidateResources); + } + if (value != null) { if (!value.ContainsOwner(this)) @@ -743,7 +750,7 @@ public ResourceDictionary Resources // final invalidation & it is no worse than the old code that also did not invalidate in this case // Removed the not-empty check to allow invalidations in the case that the old dictionary // is replaced with a new empty dictionary - if (oldValue != value) + if (oldValue != value || invalidateResources) { TreeWalkHelper.InvalidateOnResourcesChange(this, null, new ResourcesChangeInfo(oldValue, value)); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TreeWalkHelper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TreeWalkHelper.cs index 7d3dded9a88..aeb57c9cf38 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TreeWalkHelper.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TreeWalkHelper.cs @@ -459,9 +459,13 @@ internal static void InvalidateOnResourcesChange( // Here we are syncing the window's Theme mode if resource dictionary changes. // The IgnoreWindowResourcesChange is a flag set to make sure the ThemeMode change does not cause an infinite loop of resource changes. - if(fe is Window currentWindow && !ThemeManager.IgnoreWindowResourcesChange) + if(fe is Window currentWindow) { - ThemeManager.SyncWindowThemeModeAndResources(currentWindow); + currentWindow.AreResourcesInitialized = true; + if(!ThemeManager.IgnoreWindowResourcesChange) + { + ThemeManager.SyncWindowThemeModeAndResources(currentWindow); + } } // We're interested in changes to the Template property that occur during diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Window.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Window.cs index c4b88361334..c64dcaaf51b 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Window.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Window.cs @@ -583,6 +583,14 @@ public ThemeMode ThemeMode ThemeMode oldTheme = _themeMode; _themeMode = value; + if(!AreResourcesInitialized) + { + ThemeManager.OnWindowThemeChanged(this, oldTheme, value); + AreResourcesInitialized = false; + + ReloadFluentDictionary = true; + } + if(IsSourceWindowNull) { _deferThemeLoading = true; @@ -2120,6 +2128,23 @@ internal Point LogicalToDeviceUnits(Point ptLogicalUnits) return ptDeviceUnits; } + internal void AddFluentDictionary(ResourceDictionary value, out bool invalidateResources) + { + invalidateResources = false; + + if(this.ReloadFluentDictionary && !this.AreResourcesInitialized) + { + if(value != null) + { + var uri = ThemeManager.GetThemeResource(this.ThemeMode); + value.MergedDictionaries.Insert(0, new ResourceDictionary() { Source = uri }); + invalidateResources = true; + } + + this.ReloadFluentDictionary = false; + } + } + internal static bool VisibilityToBool(Visibility v) { switch (v) @@ -3292,6 +3317,31 @@ bool IWindowService.UserResized { get { return false; } } + + private bool ReloadFluentDictionary + { + get + { + return _reloadFluentDictionary; + } + set + { + _reloadFluentDictionary = value; + } + } + + internal bool AreResourcesInitialized + { + get + { + return _resourcesInitialized; + } + set + { + _resourcesInitialized = value; + } + } + #endregion Internal Properties //---------------------------------------------- @@ -7215,7 +7265,9 @@ private EventHandlerList Events private SourceWindowHelper _swh; // object that will hold the window private Window _ownerWindow; // owner window - + private bool _reloadFluentDictionary = false; + private bool _resourcesInitialized = false; + // keeps track of the owner hwnd // we need this one b/c a owner/parent // can be set through the WindowInteropHandler From 42c76ac5a2f42b802267a47df755b1b698a25cf8 Mon Sep 17 00:00:00 2001 From: hmishra Date: Wed, 14 Aug 2024 12:16:43 +0530 Subject: [PATCH 5/7] Code refactor and clean-up --- .../System/Windows/Window.cs | 20 ++++--------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Window.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Window.cs index c64dcaaf51b..d9e8c32e154 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Window.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Window.cs @@ -588,7 +588,7 @@ public ThemeMode ThemeMode ThemeManager.OnWindowThemeChanged(this, oldTheme, value); AreResourcesInitialized = false; - ReloadFluentDictionary = true; + _reloadFluentDictionary = true; } if(IsSourceWindowNull) @@ -2132,16 +2132,16 @@ internal void AddFluentDictionary(ResourceDictionary value, out bool invalidateR { invalidateResources = false; - if(this.ReloadFluentDictionary && !this.AreResourcesInitialized) + if(_reloadFluentDictionary && !AreResourcesInitialized) { if(value != null) { - var uri = ThemeManager.GetThemeResource(this.ThemeMode); + var uri = ThemeManager.GetThemeResource(ThemeMode); value.MergedDictionaries.Insert(0, new ResourceDictionary() { Source = uri }); invalidateResources = true; } - this.ReloadFluentDictionary = false; + _reloadFluentDictionary = false; } } @@ -3318,18 +3318,6 @@ bool IWindowService.UserResized get { return false; } } - private bool ReloadFluentDictionary - { - get - { - return _reloadFluentDictionary; - } - set - { - _reloadFluentDictionary = value; - } - } - internal bool AreResourcesInitialized { get From 61f814c72488145051020d6a47b56ca70c94ae5a Mon Sep 17 00:00:00 2001 From: Harshit Mishra Date: Wed, 14 Aug 2024 18:04:26 +0530 Subject: [PATCH 6/7] Fix build failure, and change method name for clarity --- .../src/PresentationFramework/System/Windows/Application.cs | 2 +- .../src/PresentationFramework/System/Windows/ThemeManager.cs | 4 ++-- .../PresentationFramework/System/Windows/TreeWalkHelper.cs | 2 +- .../src/PresentationFramework/System/Windows/Window.cs | 3 +-- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Application.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Application.cs index 1bb07063916..58916d1817d 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Application.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Application.cs @@ -1752,7 +1752,7 @@ internal void InvalidateResourceReferences(ResourcesChangeInfo info) if (!info.IsIndividualResourceChange && !ThemeManager.SkipAppThemeModeSyncing) { - ThemeManager.SyncThemeMode(); + ThemeManager.SyncApplicationThemeMode(); } // Invalidate ResourceReference properties on all the windows. diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/ThemeManager.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/ThemeManager.cs index 6389682b9c1..1755cdda247 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/ThemeManager.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/ThemeManager.cs @@ -124,7 +124,7 @@ internal static void OnWindowThemeChanged(Window window, ThemeMode oldThemeMode, ApplyFluentOnWindow(window); } - internal static bool SyncThemeMode() + internal static bool SyncApplicationThemeMode() { ThemeMode themeMode = GetThemeModeFromResourceDictionary(Application.Current.Resources); @@ -137,7 +137,7 @@ internal static bool SyncThemeMode() return false; } - internal static void SyncWindowThemeModeAndResources(Window window) + internal static void SyncWindowThemeMode(Window window) { ThemeMode themeMode = GetThemeModeFromResourceDictionary(window.Resources); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TreeWalkHelper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TreeWalkHelper.cs index aeb57c9cf38..7eeee1fa005 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TreeWalkHelper.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TreeWalkHelper.cs @@ -464,7 +464,7 @@ internal static void InvalidateOnResourcesChange( currentWindow.AreResourcesInitialized = true; if(!ThemeManager.IgnoreWindowResourcesChange) { - ThemeManager.SyncWindowThemeModeAndResources(currentWindow); + ThemeManager.SyncWindowThemeMode(currentWindow); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Window.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Window.cs index fcefe864aba..a15e2bb08e1 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Window.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Window.cs @@ -2136,8 +2136,7 @@ internal void AddFluentDictionary(ResourceDictionary value, out bool invalidateR { if(value != null) { - var uri = ThemeManager.GetThemeResource(ThemeMode); - value.MergedDictionaries.Insert(0, new ResourceDictionary() { Source = uri }); + value.MergedDictionaries.Insert(0, ThemeManager.GetThemeDictionary(ThemeMode)); invalidateResources = true; } From e65c17cb8e176ef5148c1cd5f80d47ea34bc363a Mon Sep 17 00:00:00 2001 From: Harshit Mishra Date: Wed, 14 Aug 2024 18:17:12 +0530 Subject: [PATCH 7/7] Mitigating NullReferenceException --- .../src/PresentationFramework/System/Windows/Window.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Window.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Window.cs index a15e2bb08e1..600881ccd63 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Window.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Window.cs @@ -2134,7 +2134,7 @@ internal void AddFluentDictionary(ResourceDictionary value, out bool invalidateR if(_reloadFluentDictionary && !AreResourcesInitialized) { - if(value != null) + if(value != null && ThemeMode != ThemeMode.None) { value.MergedDictionaries.Insert(0, ThemeManager.GetThemeDictionary(ThemeMode)); invalidateResources = true;