forked from Kinnara/ModernWpf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathThemeManagerProxy.cs
136 lines (108 loc) · 4.05 KB
/
ThemeManagerProxy.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
using ModernWpf;
using System.ComponentModel;
using System.Windows.Media;
namespace SamplesCommon
{
public class ThemeManagerProxy : BindableBase
{
private ThemeManagerProxy()
{
DispatcherHelper.RunOnMainThread(() =>
{
DependencyPropertyDescriptor.FromProperty(ThemeManager.ApplicationThemeProperty, typeof(ThemeManager))
.AddValueChanged(ThemeManager.Current, delegate { UpdateApplicationTheme(); });
DependencyPropertyDescriptor.FromProperty(ThemeManager.ActualApplicationThemeProperty, typeof(ThemeManager))
.AddValueChanged(ThemeManager.Current, delegate { UpdateActualApplicationTheme(); });
DependencyPropertyDescriptor.FromProperty(ThemeManager.AccentColorProperty, typeof(ThemeManager))
.AddValueChanged(ThemeManager.Current, delegate { UpdateAccentColor(); });
DependencyPropertyDescriptor.FromProperty(ThemeManager.ActualAccentColorProperty, typeof(ThemeManager))
.AddValueChanged(ThemeManager.Current, delegate { UpdateActualAccentColor(); });
UpdateApplicationTheme();
UpdateActualApplicationTheme();
UpdateAccentColor();
UpdateActualAccentColor();
});
}
public static ThemeManagerProxy Current { get; } = new ThemeManagerProxy();
#region ApplicationTheme
public ApplicationTheme? ApplicationTheme
{
get => _applicationTheme;
set
{
if (_applicationTheme != value)
{
Set(ref _applicationTheme, value);
if (!_updatingApplicationTheme)
{
DispatcherHelper.RunOnMainThread(() =>
{
ThemeManager.Current.ApplicationTheme = _applicationTheme;
});
}
}
}
}
private void UpdateApplicationTheme()
{
_updatingApplicationTheme = true;
ApplicationTheme = ThemeManager.Current.ApplicationTheme;
_updatingApplicationTheme = false;
}
private ApplicationTheme? _applicationTheme;
private bool _updatingApplicationTheme;
#endregion
#region ActualApplicationTheme
public ApplicationTheme ActualApplicationTheme
{
get => _actualApplicationTheme;
private set => Set(ref _actualApplicationTheme, value);
}
private void UpdateActualApplicationTheme()
{
ActualApplicationTheme = ThemeManager.Current.ActualApplicationTheme;
}
private ApplicationTheme _actualApplicationTheme;
#endregion
#region AccentColor
public Color? AccentColor
{
get => _accentColor;
set
{
if (_accentColor != value)
{
Set(ref _accentColor, value);
if (!_updatingAccentColor)
{
DispatcherHelper.RunOnMainThread(() =>
{
ThemeManager.Current.AccentColor = _accentColor;
});
}
}
}
}
private void UpdateAccentColor()
{
_updatingAccentColor = true;
AccentColor = ThemeManager.Current.AccentColor;
_updatingAccentColor = false;
}
private Color? _accentColor;
private bool _updatingAccentColor;
#endregion
#region ActualAccentColor
public Color ActualAccentColor
{
get => _actualAccentColor;
private set => Set(ref _actualAccentColor, value);
}
private void UpdateActualAccentColor()
{
ActualAccentColor = ThemeManager.Current.ActualAccentColor;
}
private Color _actualAccentColor;
#endregion
}
}