Skip to content

Commit 0d3bd11

Browse files
committed
Some work on the new MahApps themes... BornToBeRoot#309
1 parent 898dd57 commit 0d3bd11

11 files changed

Lines changed: 64 additions & 471 deletions

Source/NETworkManager.Converters/AppThemeToBrushConverter.cs

Lines changed: 0 additions & 42 deletions
This file was deleted.

Source/NETworkManager.Converters/AppThemeToStringConverter.cs

Lines changed: 0 additions & 44 deletions
This file was deleted.
Lines changed: 26 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,56 @@
1-
using MahApps.Metro;
1+
using ControlzEx.Theming;
22
using MahApps.Metro.Controls.Dialogs;
3-
using System;
43
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;
69

710
namespace NETworkManager.Settings
811
{
912
public static class AppearanceManager
1013
{
14+
15+
1116
private static readonly string ThemesFilePath = Path.Combine(ConfigurationManager.Current.ExecutionPath, "Themes");
1217

13-
private const string CostomThemeFileExtension = @".Theme.xaml";
14-
private const string CostomAccentFileExtension = @".Accent.xaml";
15-
1618
public static MetroDialogSettings MetroDialog = new MetroDialogSettings();
1719

20+
21+
1822
public static void Load()
1923
{
20-
// Add custom themes
21-
//foreach (var file in Directory.GetFiles(ThemesFilePath))
22-
//{
23-
// var fileName = Path.GetFileName(file);
2424

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");
2826

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();
3332

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;
3634

37-
//if (!string.IsNullOrEmpty(appThemeName) && appThemeName != ThemeManager.DetectAppStyle().Item1.Name)
38-
// ChangeAppTheme(appThemeName);
35+
36+
var theme = ThemeManager.Current.DetectTheme(System.Windows.Application.Current);
3937

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)));
4241

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-
//};
5042
}
5143

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)
5746
{
58-
//var theme = ThemeManager.GetAppTheme(name);
5947

60-
//// If user has renamed / removed a custom theme --> fallback default
61-
//if (theme != null)
62-
// ThemeManager.ChangeAppTheme(System.Windows.Application.Current, name);
6348
}
6449

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)
7052
{
71-
//var appStyle = ThemeManager.DetectAppStyle(System.Windows.Application.Current);
72-
//var accent = ThemeManager.GetAccent(name);
7353

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);
7754
}
7855
}
7956
}

Source/NETworkManager.Settings/NETworkManager.Settings.csproj

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,12 @@
2222
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
2323
</None>
2424
</ItemGroup>
25-
<ItemGroup>
26-
<Content Include="Themes\Black.Accent.xaml">
27-
<Generator></Generator>
28-
<SubType>Designer</SubType>
29-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
30-
</Content>
31-
<Content Include="Themes\Black.Theme.xaml">
32-
<SubType>Designer</SubType>
33-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
34-
</Content>
35-
<Content Include="Themes\White.Theme.xaml">
36-
<SubType>Designer</SubType>
37-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
38-
</Content>
39-
</ItemGroup>
4025
<ItemGroup>
4126
<ProjectReference Include="..\NETworkManager.Controls\NETworkManager.Controls.csproj" />
4227
<ProjectReference Include="..\NETworkManager.Models\NETworkManager.Models.csproj" />
4328
<ProjectReference Include="..\NETworkManager.Utilities\NETworkManager.Utilities.csproj" />
4429
</ItemGroup>
30+
<ItemGroup>
31+
<Folder Include="Themes\" />
32+
</ItemGroup>
4533
</Project>

Source/NETworkManager.Settings/Themes/Black.Accent.xaml

Lines changed: 0 additions & 54 deletions
This file was deleted.

0 commit comments

Comments
 (0)