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 a70940d98de..852f7920388 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/ThemeManager.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/ThemeManager.cs @@ -182,6 +182,16 @@ internal static void SyncDeferredThemeModeAndResources() internal static void SyncWindowThemeModeAndResources(Window window) { + + if(window._deferThemeLoading) + { + IgnoreWindowResourcesChange = true; + var uri = GetThemeResource(window.ThemeMode); + window.Resources.MergedDictionaries.Insert(0, new ResourceDictionary() { Source = uri }); + window._deferThemeLoading = false; + IgnoreWindowResourcesChange = false; + } + ThemeMode themeMode = GetThemeModeFromResourceDictionary(window.Resources); if(window.ThemeMode != themeMode) 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..71f21ef5e1c 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Window.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Window.cs @@ -2573,7 +2573,7 @@ internal void CreateSourceWindow(bool duringShow) } } - if(_deferThemeLoading) + if(_deferThemeLoading || ThemeMode != ThemeMode.None) { _deferThemeLoading = false; ThemeManager.OnWindowThemeChanged(this, ThemeMode.None, ThemeMode);