Skip to content

Commit

Permalink
fix(ResourceDictionary): Default theme may not be valid on first call
Browse files Browse the repository at this point in the history
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 unoplatform/Uno.Gallery@9fbf149. The background should be dark when system settings are dark.
  • Loading branch information
jeromelaban committed Jan 8, 2021
1 parent 58b4b7b commit 47b6aed
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/Uno.UI/UI/Xaml/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public partial class Application
private bool _themeSetExplicitly = false;
private ApplicationTheme? _requestedTheme;
private bool _systemThemeChangesObserved = false;
private string _requestedThemeForResources;

static Application()
{
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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
{
Expand Down

0 comments on commit 47b6aed

Please sign in to comment.