Skip to content

Commit 80eb2b8

Browse files
committed
Fix Drag Window in Maximized State #234
1 parent 62f2a24 commit 80eb2b8

File tree

2 files changed

+45
-19
lines changed

2 files changed

+45
-19
lines changed

src/Shared/HandyControl_Shared/Controls/Window/Window.cs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Runtime.InteropServices;
33
using System.Windows;
4-
using System.Windows.Data;
54
using System.Windows.Input;
65
using System.Windows.Media;
76
using HandyControl.Data;
@@ -55,24 +54,7 @@ static Window()
5554

5655
public Window()
5756
{
58-
#if NET40
59-
var chrome = new WindowChrome
60-
{
61-
CornerRadius = new CornerRadius(),
62-
GlassFrameThickness = new Thickness(0, 0, 0, 1)
63-
};
64-
#else
65-
var chrome = new WindowChrome
66-
{
67-
CornerRadius = new CornerRadius(),
68-
ResizeBorderThickness = new Thickness(8),
69-
GlassFrameThickness = new Thickness(0, 0, 0, 1),
70-
UseAeroCaptionButtons = false
71-
};
72-
#endif
73-
BindingOperations.SetBinding(chrome, WindowChrome.CaptionHeightProperty,
74-
new Binding(NonClientAreaHeightProperty.Name) { Source = this });
75-
WindowChrome.SetWindowChrome(this, chrome);
57+
ApplyWindowChrome(WindowState);
7658
_commonPadding = Padding;
7759

7860
Loaded += (s, e) => OnLoaded(e);

src/Shared/HandyControl_Shared/HandyControls/Controls/Window!.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
using System;
22
using System.Windows;
33
using System.Windows.Controls;
4+
using System.Windows.Data;
45
using System.Windows.Interop;
56
using System.Windows.Media;
7+
using System.Windows.Shell;
68
using HandyControl.Data;
79
using HandyControl.Tools;
810
using HandyControl.Tools.Interop;
@@ -135,4 +137,46 @@ private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
135137
FixCut();
136138
}
137139
}
140+
141+
private void ApplyWindowChrome(WindowState windowsState)
142+
{
143+
#if NET40
144+
var chrome = new WindowChrome
145+
{
146+
CornerRadius = new CornerRadius(),
147+
GlassFrameThickness = new Thickness(0, 0, 0, 1)
148+
};
149+
#else
150+
var chrome = new WindowChrome()
151+
{
152+
CaptionHeight = NonClientAreaHeight - 7,
153+
CornerRadius = new CornerRadius(8),
154+
GlassFrameThickness = new Thickness(-1),
155+
ResizeBorderThickness = new Thickness(6)
156+
};
157+
if (windowsState == WindowState.Maximized)
158+
{
159+
chrome.ResizeBorderThickness = new Thickness(0);
160+
}
161+
else
162+
{
163+
chrome.ResizeBorderThickness = new Thickness(6);
164+
}
165+
#endif
166+
BindingOperations.SetBinding(chrome, WindowChrome.CaptionHeightProperty,
167+
new Binding(NonClientAreaHeightProperty.Name) { Source = this });
168+
WindowChrome.SetWindowChrome(this, chrome);
169+
}
170+
171+
#if !NET40
172+
protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
173+
{
174+
if (e.Property.Name is nameof(WindowState))
175+
{
176+
ApplyWindowChrome((WindowState) e.NewValue);
177+
}
178+
base.OnPropertyChanged(e);
179+
}
180+
#endif
181+
138182
}

0 commit comments

Comments
 (0)