|
1 | | -using MahApps.Metro; |
| 1 | +using ControlzEx.Theming; |
2 | 2 | using MahApps.Metro.Controls.Dialogs; |
3 | | -using System; |
4 | 3 | using System.IO; |
5 | | -using System.Windows; |
| 4 | +using System.Windows.Media; |
| 5 | +using System.Linq; |
| 6 | +using System.Collections.Generic; |
| 7 | +using System; |
| 8 | +using System.Diagnostics; |
6 | 9 |
|
7 | 10 | namespace NETworkManager.Settings |
8 | 11 | { |
9 | 12 | public static class AppearanceManager |
10 | 13 | { |
| 14 | + |
| 15 | + |
11 | 16 | private static readonly string ThemesFilePath = Path.Combine(ConfigurationManager.Current.ExecutionPath, "Themes"); |
12 | 17 |
|
13 | | - private const string CostomThemeFileExtension = @".Theme.xaml"; |
14 | | - private const string CostomAccentFileExtension = @".Accent.xaml"; |
15 | | - |
16 | 18 | public static MetroDialogSettings MetroDialog = new MetroDialogSettings(); |
17 | 19 |
|
| 20 | + |
| 21 | + |
18 | 22 | public static void Load() |
19 | 23 | { |
20 | | - // Add custom themes |
21 | | - //foreach (var file in Directory.GetFiles(ThemesFilePath)) |
22 | | - //{ |
23 | | - // var fileName = Path.GetFileName(file); |
24 | 24 |
|
25 | | - // // Theme |
26 | | - // if (fileName.EndsWith(CostomThemeFileExtension)) |
27 | | - // ThemeManager.AddAppTheme(fileName.Substring(0, fileName.Length - CostomThemeFileExtension.Length), new Uri(file)); |
| 25 | + ThemeManager.Current.ChangeTheme(System.Windows.Application.Current, "Dark.Teal"); |
28 | 26 |
|
29 | | - // // Accent |
30 | | - // if (fileName.EndsWith(CostomAccentFileExtension)) |
31 | | - // ThemeManager.AddAccent(fileName.Substring(0, fileName.Length - CostomAccentFileExtension.Length), new Uri(file)); |
32 | | - //} |
| 27 | + var Colors = typeof(Colors) |
| 28 | + .GetProperties() |
| 29 | + .Where(prop => typeof(Color).IsAssignableFrom(prop.PropertyType)) |
| 30 | + .Select(prop => new KeyValuePair<String, Color>(prop.Name, (Color)prop.GetValue(null))) |
| 31 | + .ToList(); |
33 | 32 |
|
34 | | - //// Change the AppTheme if it is not empty and different from the currently loaded |
35 | | - //var appThemeName = SettingsManager.Current.Appearance_AppTheme; |
| 33 | + var selectedColor = Colors.FirstOrDefault(x => x.Key == "WhiteSmoke").Value; |
36 | 34 |
|
37 | | - //if (!string.IsNullOrEmpty(appThemeName) && appThemeName != ThemeManager.DetectAppStyle().Item1.Name) |
38 | | - // ChangeAppTheme(appThemeName); |
| 35 | + |
| 36 | + var theme = ThemeManager.Current.DetectTheme(System.Windows.Application.Current); |
39 | 37 |
|
40 | | - //// Change the Accent if it is not empty and different from the currently loaded |
41 | | - //var accentName = SettingsManager.Current.Appearance_Accent; |
| 38 | + var inverseTheme = ThemeManager.Current.GetInverseTheme(theme); |
| 39 | + ThemeManager.Current.AddTheme(RuntimeThemeGenerator.Current.GenerateRuntimeTheme(inverseTheme.BaseColorScheme, selectedColor)); |
| 40 | + ThemeManager.Current.ChangeTheme(System.Windows.Application.Current, ThemeManager.Current.AddTheme(RuntimeThemeGenerator.Current.GenerateRuntimeTheme(theme.BaseColorScheme, selectedColor))); |
42 | 41 |
|
43 | | - //if (!string.IsNullOrEmpty(accentName) && accentName != ThemeManager.DetectAppStyle().Item2.Name) |
44 | | - // ChangeAccent(accentName); |
45 | | - |
46 | | - //MetroDialog.CustomResourceDictionary = new ResourceDictionary |
47 | | - //{ |
48 | | - // Source = new Uri("NETworkManager;component/Resources/Styles/MetroDialogStyles.xaml", UriKind.RelativeOrAbsolute) |
49 | | - //}; |
50 | 42 | } |
51 | 43 |
|
52 | | - /// <summary> |
53 | | - /// Change the AppTheme |
54 | | - /// </summary> |
55 | | - /// <param name="name">Name of the AppTheme</param> |
56 | | - public static void ChangeAppTheme(string name) |
| 44 | + |
| 45 | + public static void ChangeTheme(string name) |
57 | 46 | { |
58 | | - //var theme = ThemeManager.GetAppTheme(name); |
59 | 47 |
|
60 | | - //// If user has renamed / removed a custom theme --> fallback default |
61 | | - //if (theme != null) |
62 | | - // ThemeManager.ChangeAppTheme(System.Windows.Application.Current, name); |
63 | 48 | } |
64 | 49 |
|
65 | | - /// <summary> |
66 | | - /// Change the Accent |
67 | | - /// </summary> |
68 | | - /// <param name="name">Name of the Accent</param> |
69 | | - public static void ChangeAccent(string name) |
| 50 | + |
| 51 | + public static void ChangeColor(string name) |
70 | 52 | { |
71 | | - //var appStyle = ThemeManager.DetectAppStyle(System.Windows.Application.Current); |
72 | | - //var accent = ThemeManager.GetAccent(name); |
73 | 53 |
|
74 | | - //// If user has renamed / removed a custom theme --> fallback default |
75 | | - //if (accent != null) |
76 | | - // ThemeManager.ChangeAppStyle(System.Windows.Application.Current, accent, appStyle.Item1); |
77 | 54 | } |
78 | 55 | } |
79 | 56 | } |
0 commit comments