Skip to content

Commit 2fd6514

Browse files
committed
更新 v3.0.40
1 parent ab8d593 commit 2fd6514

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

CoolapkUWP/CoolapkUWP/Helpers/ThemeHelper.cs

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,20 @@ public static ElementTheme ActualTheme
2929
{
3030
get
3131
{
32-
return CurrentApplicationWindow?.Dispatcher?.HasThreadAccess == true
33-
? CurrentApplicationWindow?.Content is FrameworkElement rootElement
34-
&& rootElement.RequestedTheme != ElementTheme.Default
35-
? rootElement.RequestedTheme
36-
: SettingsHelper.Get<ElementTheme>(SettingsHelper.SelectedAppTheme)
37-
: UIHelper.AwaitByTaskCompleteSource(() =>
38-
CurrentApplicationWindow?.Dispatcher?.AwaitableRunAsync(() =>
39-
CurrentApplicationWindow?.Content is FrameworkElement _rootElement
40-
&& _rootElement.RequestedTheme != ElementTheme.Default
41-
? _rootElement.RequestedTheme
42-
: SettingsHelper.Get<ElementTheme>(SettingsHelper.SelectedAppTheme),
43-
CoreDispatcherPriority.High));
32+
return CurrentApplicationWindow == null
33+
? SettingsHelper.Get<ElementTheme>(SettingsHelper.SelectedAppTheme)
34+
: CurrentApplicationWindow.Dispatcher.HasThreadAccess
35+
? CurrentApplicationWindow.Content is FrameworkElement rootElement
36+
&& rootElement.RequestedTheme != ElementTheme.Default
37+
? rootElement.RequestedTheme
38+
: SettingsHelper.Get<ElementTheme>(SettingsHelper.SelectedAppTheme)
39+
: UIHelper.AwaitByTaskCompleteSource(() =>
40+
CurrentApplicationWindow.Dispatcher.AwaitableRunAsync(() =>
41+
CurrentApplicationWindow.Content is FrameworkElement _rootElement
42+
&& _rootElement.RequestedTheme != ElementTheme.Default
43+
? _rootElement.RequestedTheme
44+
: SettingsHelper.Get<ElementTheme>(SettingsHelper.SelectedAppTheme),
45+
CoreDispatcherPriority.High));
4446
}
4547
}
4648

@@ -53,22 +55,24 @@ public static ElementTheme RootTheme
5355
{
5456
return CurrentApplicationWindow == null
5557
? ElementTheme.Default
56-
: CurrentApplicationWindow.Dispatcher.HasThreadAccess
58+
: CurrentApplicationWindow.Dispatcher.HasThreadAccess
5759
? CurrentApplicationWindow.Content is FrameworkElement rootElement
5860
? rootElement.RequestedTheme
5961
: ElementTheme.Default
60-
: UIHelper.AwaitByTaskCompleteSource(() =>
61-
CurrentApplicationWindow.Dispatcher.AwaitableRunAsync(() =>
62-
CurrentApplicationWindow.Content is FrameworkElement _rootElement
63-
? _rootElement.RequestedTheme
64-
: ElementTheme.Default,
65-
CoreDispatcherPriority.High));
62+
: UIHelper.AwaitByTaskCompleteSource(() =>
63+
CurrentApplicationWindow.Dispatcher.AwaitableRunAsync(() =>
64+
CurrentApplicationWindow.Content is FrameworkElement _rootElement
65+
? _rootElement.RequestedTheme
66+
: ElementTheme.Default,
67+
CoreDispatcherPriority.High));
6668
}
6769
set
6870
{
69-
_ = CurrentApplicationWindow?.Dispatcher?.AwaitableRunAsync(() =>
71+
if (CurrentApplicationWindow == null) { return; }
72+
73+
_ = CurrentApplicationWindow.Dispatcher.AwaitableRunAsync(() =>
7074
{
71-
if (CurrentApplicationWindow?.Content is FrameworkElement rootElement)
75+
if (CurrentApplicationWindow.Content is FrameworkElement rootElement)
7276
{
7377
rootElement.RequestedTheme = value;
7478
}

0 commit comments

Comments
 (0)