Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ResourceDictionary): Default theme may not be valid on first call #4857

Merged
merged 1 commit into from
Jan 11, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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