-
Notifications
You must be signed in to change notification settings - Fork 1
/
SystemTheme.cs
55 lines (54 loc) · 1.65 KB
/
SystemTheme.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
namespace ThemeSelector
{
/// <summary>
/// Provides an encapsulation of Application.Current.RequestedTheme
/// and Application.Current.RequestedThemeChanged to address
/// platform-specific issues.
/// </summary>
public static class SystemTheme
{
/// <summary>
/// Gets the system's <see cref="AppTheme"/>.
/// </summary>
/// <remarks>
/// This property is an alternative to Application.Current.RequestedTheme.
/// </remarks>
public static AppTheme RequestedTheme
{
get
{
#if (ANDROID)
// See https://github.com/dotnet/maui/issues/8236
return ThemeSelector.Platforms.Android.ThemeInfo.Theme;
#else
return Application.Current.RequestedTheme;
#endif
}
}
/// <summary>
/// Occurs when the system <see cref="RequestedTheme"/> changes.
/// </summary>
/// <remarks>
/// This event is an alternative to Application.Current.RequestedThemeChanged.
/// </remarks>
public static event EventHandler<AppThemeChangedEventArgs> RequestedThemeChanged
{
add
{
#if (ANDROID)
ThemeSelector.Platforms.Android.ThemeInfo.RequestedThemeChanged += value;
#else
Application.Current.RequestedThemeChanged += value;
#endif
}
remove
{
#if (ANDROID)
ThemeSelector.Platforms.Android.ThemeInfo.RequestedThemeChanged -= value;
#else
Application.Current.RequestedThemeChanged -= value;
#endif
}
}
}
}