-
Notifications
You must be signed in to change notification settings - Fork 2
/
ModernWindow.xaml.cs
156 lines (139 loc) · 4.89 KB
/
ModernWindow.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Shell;
namespace AdvancedWindowsAppearence
{
/// <summary>
/// Interaction logic for ModernWindow.xaml
/// </summary>
public partial class ModernWindow : Window
{
bool IsLightMode = true;
int MaximizeOffset = 5;
public ModernWindow(bool? isLightMode)
{
if(isLightMode != null)
IsLightMode = isLightMode.Value;
UpdateTheme(IsLightMode);
InitializeComponent();
}
/// <summary>
/// Update Ui by the selected theme
/// </summary>
public void UpdateTheme(bool isLightMode)
{
if (!isLightMode) //force dark mode
{
App.Current.Resources["ButtonFaceColor"] = new BrushConverter().ConvertFromString("#FF404040");
App.Current.Resources["BackgroundColor"] = Brushes.Black;
App.Current.Resources["BackgroundColorTabItems"] = new BrushConverter().ConvertFromString("#9F252525");
App.Current.Resources["ForegroundColor"] = Brushes.White;
}
else
{
App.Current.Resources["ButtonFaceColor"] = SystemColors.ControlBrush;
App.Current.Resources["BackgroundColor"] = SystemColors.WindowBrush;
App.Current.Resources["BackgroundColorTabItems"] = new BrushConverter().ConvertFromString("#BFFFFFFF");
App.Current.Resources["ForegroundColor"] = SystemColors.WindowTextBrush;
}
IsLightMode = isLightMode;
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
WindowRounding.RoundWindow(this);
WindowShadow.DropShadowToWindow(this);
WindowBlur.SetIsEnabled(this, true);
AdjustBorder();
}
/// <summary>
/// if the window rounding is enabled, adjust the border to it
/// </summary>
private void AdjustBorder()
{
if (!WindowRounding.IsRoundingEnabled.HasValue)
return;
if (!WindowRounding.IsRoundingEnabled.Value) //if is rounding disabled
return;
windowBorder.CornerRadius = new CornerRadius(8.0);
windowBorder.BorderThickness = new Thickness(2);
MaximizeOffset = 4;
}
private void window_Activated(object sender, EventArgs e)
{
this.Background = (SolidColorBrush)new BrushConverter().ConvertFromString("#33000000");
titlebarGrid.Opacity = 1;
windowBorder.BorderBrush = (Brush)App.Current.Resources["ThemeColor"];
windowBorder.Opacity = 1;
}
private void window_Deactivated(object sender, EventArgs e)
{
if (IsLightMode)
this.Background = System.Windows.Media.Brushes.Gray;
else
this.Background = (SolidColorBrush)new BrushConverter().ConvertFromString("#FF101010");
titlebarGrid.Opacity = 0.4;
windowBorder.BorderBrush = Brushes.Gray;
windowBorder.Opacity = 0.4;
}
#region Caption Buttons and actions
void Minimize()
{
SystemCommands.MinimizeWindow(this);
}
void Maximize()
{
masterGrid.Margin = new Thickness(MaximizeOffset);
SystemCommands.MaximizeWindow(this);
maximizeButton.Content = "";
}
void Restore()
{
masterGrid.Margin = new Thickness(0);
SystemCommands.RestoreWindow(this);
maximizeButton.Content = "";
}
private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
{
if (e.LeftButton != MouseButtonState.Pressed)
return;
if (this.WindowState != WindowState.Normal)
{
Restore();
return;
}
this.DragMove();
}
private void minimizeButton_Click(object sender, RoutedEventArgs e)
{
Minimize();
}
private void maximizeButton_Click(object sender, RoutedEventArgs e)
{
if (this.WindowState != WindowState.Maximized)
{
this.MaxHeight = SystemParameters.MaximizedPrimaryScreenHeight;
Maximize();
}
else
{
Restore();
}
}
private void closeButton_Click_1(object sender, RoutedEventArgs e)
{
this.Close();
}
#endregion
}
}