Skip to content

Commit

Permalink
Merge pull request #4857 from unoplatform/dev/jela/default-theme-fix
Browse files Browse the repository at this point in the history
fix(ResourceDictionary): Default theme may not be valid on first call
  • Loading branch information
jeromelaban committed Jan 11, 2021
2 parents c560d50 + 47b6aed commit e4e76b6
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 e4e76b6

Please sign in to comment.