From 47b6aed129b22731e7eb2e7ea20c86f0a3277d21 Mon Sep 17 00:00:00 2001 From: Jerome Laban Date: Fri, 8 Jan 2021 17:31:50 -0500 Subject: [PATCH] fix(ResourceDictionary): Default theme may not be valid on first call There are no tests for this specific change as it impacts the Application.Current. The validation for this change can be done through the Uno Gallery at https://github.com/unoplatform/Uno.Gallery/commit/9fbf14903b7ca0d3d3cac48c8bc51e5790590c51. The background should be dark when system settings are dark. --- src/Uno.UI/UI/Xaml/Application.cs | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/Uno.UI/UI/Xaml/Application.cs b/src/Uno.UI/UI/Xaml/Application.cs index 210b2d0ab8a4..a4687af56126 100644 --- a/src/Uno.UI/UI/Xaml/Application.cs +++ b/src/Uno.UI/UI/Xaml/Application.cs @@ -46,6 +46,7 @@ public partial class Application private bool _themeSetExplicitly = false; private ApplicationTheme? _requestedTheme; private bool _systemThemeChangesObserved = false; + private string _requestedThemeForResources; static Application() { @@ -81,11 +82,7 @@ public ApplicationTheme RequestedTheme { get { - if (InternalRequestedTheme == null) - { - // just cache the theme, but do not notify about a change unnecessarily - InternalRequestedTheme = GetDefaultSystemTheme(); - } + EnsureInternalRequestedTheme(); return InternalRequestedTheme.Value; } set @@ -98,6 +95,15 @@ public ApplicationTheme RequestedTheme } } + private void EnsureInternalRequestedTheme() + { + if (InternalRequestedTheme == null) + { + // just cache the theme, but do not notify about a change unnecessarily + InternalRequestedTheme = GetDefaultSystemTheme(); + } + } + private ApplicationTheme? InternalRequestedTheme { get => _requestedTheme; @@ -120,7 +126,16 @@ internal static void UpdateRequestedThemesForResources() }; } - internal string RequestedThemeForResources { get; private set; } + internal string RequestedThemeForResources + { + get + { + EnsureInternalRequestedTheme(); + return _requestedThemeForResources; + } + + private set => _requestedThemeForResources = value; + } internal ElementTheme ActualElementTheme => (_themeSetExplicitly, RequestedTheme) switch {