-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApp.xaml.cs
54 lines (43 loc) · 1.78 KB
/
App.xaml.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
using System.Reflection;
using System.Windows;
using System;
namespace NorthHorizon.Samples.SystemThemeChange
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
public App() : this(Environment.GetCommandLineArgs()) { }
public App(string[] args)
{
//SetTheme("luna", "normalcolor");
//ThemeHelper.SetTheme("luna", "normalcolor");
if (args.Length >= 2)
{
string theme = args[1], color = null;
if (args.Length >= 3)
color = args[2];
ThemeHelper.SetTheme(theme, color);
}
}
/// <summary>
/// Sets the WPF system theme.
/// </summary>
/// <param name="themeName">The name of the theme. (ie "aero")</param>
/// <param name="themeColor">The name of the color. (ie "normalcolor")</param>
public static void SetTheme(string themeName, string themeColor)
{
const BindingFlags staticNonPublic = BindingFlags.Static | BindingFlags.NonPublic;
var presentationFrameworkAsm = Assembly.GetAssembly(typeof(Window));
var themeWrapper = presentationFrameworkAsm.GetType("MS.Win32.UxThemeWrapper");
var isActiveField = themeWrapper.GetField("_isActive", staticNonPublic);
var themeColorField = themeWrapper.GetField("_themeColor", staticNonPublic);
var themeNameField = themeWrapper.GetField("_themeName", staticNonPublic);
// Set this to true so WPF doesn't default to classic.
isActiveField.SetValue(null, true);
themeColorField.SetValue(null, themeColor);
themeNameField.SetValue(null, themeName);
}
}
}