public class ColorHelper : INotifyPropertyChanged
{
static SolidColorBrush DefaultThemeBackgroundColor
= new SolidColorBrush(Color.FromRgb(0xA3, 0xC3, 0xEC));
static SolidColorBrush DefaultThemeForegroundColor
= new SolidColorBrush(Color.FromRgb(0x00, 0x00, 0x00));
public ColorHelper()
{
ThemeManager.ThemeChanged +=
ColorHelper.ThemeChanged;
GetColors
(ThemeManager.ActualApplicationThemeName);
}
private Brush _Foreground;
private Brush _Background;
static ColorHelper _Instance;
public static ColorHelper Instance { get { if
(_Instance == null)_Instance = new ColorHelper(); return
_Instance; } }
public Brush Background
{
get { return _Background; }
set
{
if (_Background == value)
return;
_Background = value;
if (PropertyChanged != null)
PropertyChanged(this, new
PropertyChangedEventArgs("Background"));
}
}
public Brush Foreground
{
get { return _Foreground; }
set
{
if (_Foreground == value)
return;
_Foreground = value;
if (PropertyChanged != null)
PropertyChanged(this, new
PropertyChangedEventArgs("Foreground"));
}
}
public static void ThemeChanged(DependencyObject
sender, ThemeChangedRoutedEventArgs e)
{
Instance.GetColors(e.ThemeName);
}
void GetColors(string name)
{
if (name == "DeepBlue")
{
Background = DefaultThemeBackgroundColor;
Foreground = DefaultThemeForegroundColor;
return;
}
ThemeManager.ThemeChanged -=
ColorHelper.ThemeChanged;
BackgroundPanel p = new BackgroundPanel();
ThemeManager.SetThemeName(p, name);
var q = p.Background;
Background = p.Background;
Foreground = p.Foreground;
ThemeManager.ThemeChanged +=
ColorHelper.ThemeChanged;
}
public event PropertyChangedEventHandler
PropertyChanged;
}