Skip to content

Commit 47b6aed

Browse files
committed
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 unoplatform/Uno.Gallery@9fbf149. The background should be dark when system settings are dark.
1 parent 58b4b7b commit 47b6aed

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

src/Uno.UI/UI/Xaml/Application.cs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public partial class Application
4646
private bool _themeSetExplicitly = false;
4747
private ApplicationTheme? _requestedTheme;
4848
private bool _systemThemeChangesObserved = false;
49+
private string _requestedThemeForResources;
4950

5051
static Application()
5152
{
@@ -81,11 +82,7 @@ public ApplicationTheme RequestedTheme
8182
{
8283
get
8384
{
84-
if (InternalRequestedTheme == null)
85-
{
86-
// just cache the theme, but do not notify about a change unnecessarily
87-
InternalRequestedTheme = GetDefaultSystemTheme();
88-
}
85+
EnsureInternalRequestedTheme();
8986
return InternalRequestedTheme.Value;
9087
}
9188
set
@@ -98,6 +95,15 @@ public ApplicationTheme RequestedTheme
9895
}
9996
}
10097

98+
private void EnsureInternalRequestedTheme()
99+
{
100+
if (InternalRequestedTheme == null)
101+
{
102+
// just cache the theme, but do not notify about a change unnecessarily
103+
InternalRequestedTheme = GetDefaultSystemTheme();
104+
}
105+
}
106+
101107
private ApplicationTheme? InternalRequestedTheme
102108
{
103109
get => _requestedTheme;
@@ -120,7 +126,16 @@ internal static void UpdateRequestedThemesForResources()
120126
};
121127
}
122128

123-
internal string RequestedThemeForResources { get; private set; }
129+
internal string RequestedThemeForResources
130+
{
131+
get
132+
{
133+
EnsureInternalRequestedTheme();
134+
return _requestedThemeForResources;
135+
}
136+
137+
private set => _requestedThemeForResources = value;
138+
}
124139

125140
internal ElementTheme ActualElementTheme => (_themeSetExplicitly, RequestedTheme) switch
126141
{

0 commit comments

Comments
 (0)