-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathWindowBase.cs
More file actions
108 lines (90 loc) · 3.49 KB
/
WindowBase.cs
File metadata and controls
108 lines (90 loc) · 3.49 KB
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
// Copyright (c) TensorStack. All rights reserved.
// Licensed under the Apache 2.0 License.
using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Media;
namespace TensorStack.WPF.Controls
{
public class WindowBase : Window, INotifyPropertyChanged, System.Windows.Forms.IWin32Window
{
private readonly WindowInteropHelper _interopHelper;
private bool _isDialogVisible;
public WindowBase()
{
_interopHelper = new WindowInteropHelper(this);
AllowsTransparency = true;
SnapsToDevicePixels = true;
WindowStyle = WindowStyle.None;
WindowStartupLocation = WindowStartupLocation.CenterOwner;
RenderOptions.SetBitmapScalingMode(this, BitmapScalingMode.Fant);
RenderOptions.SetClearTypeHint(this, ClearTypeHint.Enabled);
TextOptions.SetTextFormattingMode(this, TextFormattingMode.Ideal);
TextOptions.SetTextRenderingMode(this, TextRenderingMode.ClearType);
TextOptions.SetTextHintingMode(this, TextHintingMode.Fixed);
CloseCommand = new AsyncRelayCommand(CloseAsync);
RestoreCommand = new AsyncRelayCommand(RestoreAsync);
MinimizeCommand = new AsyncRelayCommand(MinimizeAsync);
MaximizeCommand = new AsyncRelayCommand(MaximizeAsync);
}
public nint Handle => _interopHelper.Handle;
public AsyncRelayCommand MinimizeCommand { get; }
public AsyncRelayCommand RestoreCommand { get; }
public AsyncRelayCommand MaximizeCommand { get; }
public AsyncRelayCommand CloseCommand { get; }
public bool IsDialogVisible
{
get { return _isDialogVisible; }
set { _isDialogVisible = value; NotifyPropertyChanged(); }
}
protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);
_interopHelper.EnsureHandle();
this.RegisterDisplayMonitor();
}
protected virtual Task CloseAsync()
{
Close();
return Task.CompletedTask;
}
protected virtual Task RestoreAsync()
{
if (WindowState == WindowState.Maximized)
WindowState = WindowState.Normal;
else
WindowState = WindowState.Maximized;
return Task.CompletedTask;
}
protected virtual Task MinimizeAsync()
{
WindowState = WindowState.Minimized;
return Task.CompletedTask;
}
protected virtual Task MaximizeAsync()
{
WindowState = WindowState.Maximized;
return Task.CompletedTask;
}
#region INotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged;
public void NotifyPropertyChanged([CallerMemberName] string property = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
}
protected bool SetProperty<T>(ref T field, T newValue, [CallerMemberName] string propertyName = null)
{
if (!Equals(field, newValue))
{
field = newValue;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
return true;
}
return false;
}
#endregion
}
}