-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainWindow.xaml.cs
59 lines (48 loc) · 1.49 KB
/
MainWindow.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
55
56
57
58
59
using System;
using System.Windows;
using System.Windows.Input;
using WpfApp.Constants;
namespace WpfApp;
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
// Set initial skin
CurrentSkin = SetCurrentSkin(Global.LightSkinName);
}
private static string CurrentSkin { get; set; } = Global.LightSkinName;
private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
DragMove();
}
private void CloseButton_Click(object sender, RoutedEventArgs e)
{
Close();
}
private void MinimizeButton_Click(object sender, RoutedEventArgs e)
{
WindowState = WindowState.Minimized;
}
private void SkinButton_Click(object sender, RoutedEventArgs e)
{
CurrentSkin = ChangeSkin(CurrentSkin);
}
private static string ChangeSkin(string currentSkin)
{
return currentSkin switch
{
Global.LightSkinName => SetCurrentSkin(Global.DarkSkinName),
Global.DarkSkinName => SetCurrentSkin(Global.LightSkinName),
_ => throw new ArgumentOutOfRangeException(nameof(currentSkin), currentSkin, "Can not found theme skin.")
};
}
private static string SetCurrentSkin(string skinName)
{
Application.Current.Resources = Application.Current.Properties[skinName] as ResourceDictionary;
return skinName;
}
}