-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAMLApp.cs
62 lines (48 loc) · 1.96 KB
/
AMLApp.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
// Copyright (c) 2017 AutomationML e.V.
#nullable disable
using ControlzEx.Theming;
using System;
using System.Linq;
using System.Windows;
namespace Aml.Skins;
public static class AMLApp
{
public static Action<ResourceDictionary> ApplyColors { get; set; }
public static ResourceDictionary ThemeColors { get; set; }
public static bool IsDarkMode { get; private set; }
/// <summary>
/// Applies the skin to the application
/// </summary>
/// <param name="app">The application.</param>
/// <param name="skinDictionaryUri">The skin dictionary URI.</param>
public static void ApplySkin(Application app, Uri skinDictionaryUri)
{
// ThemeManager.Current.ThemeSyncMode = ThemeSyncMode.
// Load the ResourceDictionary into memory.
var skinDict = Application.LoadComponent(skinDictionaryUri) as ResourceDictionary;
var mergedDicts = app.Resources.MergedDictionaries;
var skinSource = @"/Aml.Skins;component/Themes";
// Remove the existing skin dictionary, if one exists.
foreach (var dict in mergedDicts.ToList())
{
if (dict.Source != null && dict.Source.OriginalString.Contains(skinSource))
{
mergedDicts.Remove(dict);
}
}
// Apply the selected skin so that all elements in the
// application will honor the new look and feel.
mergedDicts.Add(skinDict);
var theme = skinDictionaryUri.OriginalString.Contains("Dark.Styles") ? "Dark" : "Light";
ThemeManager.Current.ChangeThemeBaseColor(Application.Current, theme);
IsDarkMode = theme == "Dark";
SetColors(theme == "Dark");
}
public static void SetColors(bool isDarkMode)
{
ThemeColors = isDarkMode
? new ResourceDictionary { Source = SkinSource.DarkSkinColors }
: new ResourceDictionary { Source = SkinSource.LightSkinColors };
ApplyColors?.Invoke(ThemeColors);
}
}