Skip to content

Commit 7cc7485

Browse files
committed
Merge pull request #2326 from MahApps/2324-DragMove-fix
DragMove fix for #2324
2 parents c4ef252 + cf7510b commit 7cc7485

File tree

8 files changed

+94
-20
lines changed

8 files changed

+94
-20
lines changed

MahApps.Metro/Behaviours/BorderlessWindowBehavior.cs

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Security;
33
using System.Windows;
44
using System.Windows.Controls;
5+
using System.Windows.Controls.Primitives;
56
using System.Windows.Interactivity;
67
using System.Windows.Interop;
78
using MahApps.Metro.Controls;
@@ -340,6 +341,7 @@ private void AssociatedObject_Loaded(object sender, RoutedEventArgs e)
340341

341342
window.SetIsHitTestVisibleInChromeProperty<UIElement>("PART_Icon");
342343
window.SetIsHitTestVisibleInChromeProperty<UIElement>("PART_TitleBar");
344+
window.SetIsHitTestVisibleInChromeProperty<Thumb>("PART_WindowTitleThumb");
343345
window.SetIsHitTestVisibleInChromeProperty<ContentPresenter>("PART_LeftWindowCommands");
344346
window.SetIsHitTestVisibleInChromeProperty<ContentPresenter>("PART_RightWindowCommands");
345347
window.SetIsHitTestVisibleInChromeProperty<ContentControl>("PART_WindowButtonCommands");

MahApps.Metro/Controls/Flyout.cs

+12
Original file line numberDiff line numberDiff line change
@@ -494,10 +494,12 @@ public override void OnApplyTemplate()
494494

495495
if (this.windowTitleThumb != null)
496496
{
497+
this.windowTitleThumb.PreviewMouseLeftButtonUp -= WindowTitleThumbOnPreviewMouseLeftButtonUp;
497498
this.windowTitleThumb.DragDelta -= this.WindowTitleThumbMoveOnDragDelta;
498499
this.windowTitleThumb.MouseDoubleClick -= this.WindowTitleThumbChangeWindowStateOnMouseDoubleClick;
499500
this.windowTitleThumb.MouseRightButtonUp -= this.WindowTitleThumbSystemMenuOnMouseRightButtonUp;
500501

502+
this.windowTitleThumb.PreviewMouseLeftButtonUp += WindowTitleThumbOnPreviewMouseLeftButtonUp;
501503
this.windowTitleThumb.DragDelta += this.WindowTitleThumbMoveOnDragDelta;
502504
this.windowTitleThumb.MouseDoubleClick += this.WindowTitleThumbChangeWindowStateOnMouseDoubleClick;
503505
this.windowTitleThumb.MouseRightButtonUp += this.WindowTitleThumbSystemMenuOnMouseRightButtonUp;
@@ -520,13 +522,23 @@ protected internal void CleanUp(FlyoutsControl flyoutsControl)
520522
{
521523
if (this.windowTitleThumb != null)
522524
{
525+
this.windowTitleThumb.PreviewMouseLeftButtonUp -= WindowTitleThumbOnPreviewMouseLeftButtonUp;
523526
this.windowTitleThumb.DragDelta -= this.WindowTitleThumbMoveOnDragDelta;
524527
this.windowTitleThumb.MouseDoubleClick -= this.WindowTitleThumbChangeWindowStateOnMouseDoubleClick;
525528
this.windowTitleThumb.MouseRightButtonUp -= this.WindowTitleThumbSystemMenuOnMouseRightButtonUp;
526529
}
527530
this.parentWindow = null;
528531
}
529532

533+
private void WindowTitleThumbOnPreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
534+
{
535+
var window = this.ParentWindow;
536+
if (window != null && this.Position != Position.Bottom)
537+
{
538+
MetroWindow.DoWindowTitleThumbOnPreviewMouseLeftButtonUp(window, e);
539+
}
540+
}
541+
530542
private void WindowTitleThumbMoveOnDragDelta(object sender, DragDeltaEventArgs dragDeltaEventArgs)
531543
{
532544
var window = this.ParentWindow;

MahApps.Metro/Controls/MetroWindow.cs

+53-11
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
using MahApps.Metro.Native;
1111
using System.Windows.Shapes;
1212
using System.Collections.Generic;
13+
using System.Reflection;
1314
using System.Windows.Controls.Primitives;
15+
using System.Windows.Threading;
1416

1517
namespace MahApps.Metro.Controls
1618
{
@@ -899,11 +901,23 @@ public override void OnApplyTemplate()
899901
this.SetVisibiltyForAllTitleElements(this.TitlebarHeight > 0);
900902
}
901903

904+
protected IntPtr CriticalHandle
905+
{
906+
get
907+
{
908+
var value = typeof(Window)
909+
.GetProperty("CriticalHandle", BindingFlags.NonPublic | BindingFlags.Instance)
910+
.GetValue(this, new object[0]);
911+
return (IntPtr)value;
912+
}
913+
}
914+
902915
private void ClearWindowEvents()
903916
{
904917
// clear all event handlers first:
905918
if (this.windowTitleThumb != null)
906919
{
920+
this.windowTitleThumb.PreviewMouseLeftButtonUp -= WindowTitleThumbOnPreviewMouseLeftButtonUp;
907921
this.windowTitleThumb.DragDelta -= this.WindowTitleThumbMoveOnDragDelta;
908922
this.windowTitleThumb.MouseDoubleClick -= this.WindowTitleThumbChangeWindowStateOnMouseDoubleClick;
909923
this.windowTitleThumb.MouseRightButtonUp -= this.WindowTitleThumbSystemMenuOnMouseRightButtonUp;
@@ -928,6 +942,7 @@ private void SetWindowEvents()
928942

929943
if (this.windowTitleThumb != null)
930944
{
945+
this.windowTitleThumb.PreviewMouseLeftButtonUp += WindowTitleThumbOnPreviewMouseLeftButtonUp;
931946
this.windowTitleThumb.DragDelta += this.WindowTitleThumbMoveOnDragDelta;
932947
this.windowTitleThumb.MouseDoubleClick += this.WindowTitleThumbChangeWindowStateOnMouseDoubleClick;
933948
this.windowTitleThumb.MouseRightButtonUp += this.WindowTitleThumbSystemMenuOnMouseRightButtonUp;
@@ -955,6 +970,11 @@ private void IconMouseDown(object sender, MouseButtonEventArgs e)
955970
}
956971
}
957972

973+
private void WindowTitleThumbOnPreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
974+
{
975+
DoWindowTitleThumbOnPreviewMouseLeftButtonUp(this, e);
976+
}
977+
958978
private void WindowTitleThumbMoveOnDragDelta(object sender, DragDeltaEventArgs dragDeltaEventArgs)
959979
{
960980
DoWindowTitleThumbMoveOnDragDelta(this, dragDeltaEventArgs);
@@ -970,18 +990,24 @@ private void WindowTitleThumbSystemMenuOnMouseRightButtonUp(object sender, Mouse
970990
DoWindowTitleThumbSystemMenuOnMouseRightButtonUp(this, e);
971991
}
972992

993+
internal static void DoWindowTitleThumbOnPreviewMouseLeftButtonUp(MetroWindow window, MouseButtonEventArgs mouseButtonEventArgs)
994+
{
995+
Mouse.Capture(null);
996+
}
997+
973998
internal static void DoWindowTitleThumbMoveOnDragDelta(MetroWindow window, DragDeltaEventArgs dragDeltaEventArgs)
974999
{
9751000
// drag only if IsWindowDraggable is set to true
9761001
if (!window.IsWindowDraggable ||
977-
(!(Math.Abs(dragDeltaEventArgs.HorizontalChange) > 2) &&
978-
!(Math.Abs(dragDeltaEventArgs.VerticalChange) > 2))) return;
1002+
(!(Math.Abs(dragDeltaEventArgs.HorizontalChange) > 2) && !(Math.Abs(dragDeltaEventArgs.VerticalChange) > 2)))
1003+
{
1004+
return;
1005+
}
9791006

980-
var windowHandle = new WindowInteropHelper(window).Handle;
981-
var cursorPos = Standard.NativeMethods.GetCursorPos();
1007+
// tage from DragMove internal code
1008+
window.VerifyAccess();
9821009

983-
// for the touch usage
984-
UnsafeNativeMethods.ReleaseCapture();
1010+
var cursorPos = Standard.NativeMethods.GetCursorPos();
9851011

9861012
// if the window is maximized dragging is only allowed on title bar (also if not visible)
9871013
var windowIsMaximized = window.WindowState == WindowState.Maximized;
@@ -991,14 +1017,30 @@ internal static void DoWindowTitleThumbMoveOnDragDelta(MetroWindow window, DragD
9911017
return;
9921018
}
9931019

994-
if (windowIsMaximized)
995-
{
1020+
// for the touch usage
1021+
UnsafeNativeMethods.ReleaseCapture();
1022+
1023+
if (windowIsMaximized) {
9961024
window.Top = 2;
9971025
window.Left = Math.Max(cursorPos.x - window.RestoreBounds.Width / 2, 0);
1026+
EventHandler windowOnStateChanged = null;
1027+
windowOnStateChanged = (sender, args) =>
1028+
{
1029+
window.StateChanged -= windowOnStateChanged;
1030+
if (window.WindowState == WindowState.Normal)
1031+
{
1032+
Mouse.Capture(window.windowTitleThumb, CaptureMode.Element);
1033+
}
1034+
};
1035+
window.StateChanged += windowOnStateChanged;
9981036
}
999-
var lParam = (int)(uint)cursorPos.x | (cursorPos.y << 16);
1000-
Standard.NativeMethods.SendMessage(windowHandle, Standard.WM.LBUTTONUP, (IntPtr)Standard.HT.CAPTION, (IntPtr)lParam);
1001-
Standard.NativeMethods.SendMessage(windowHandle, Standard.WM.SYSCOMMAND, (IntPtr)Standard.SC.MOUSEMOVE, IntPtr.Zero);
1037+
1038+
var criticalHandle = window.CriticalHandle;
1039+
// DragMove works too
1040+
// window.DragMove();
1041+
// instead this 2 lines
1042+
Standard.NativeMethods.SendMessage(criticalHandle, Standard.WM.SYSCOMMAND, (IntPtr)Standard.SC.MOUSEMOVE, IntPtr.Zero);
1043+
Standard.NativeMethods.SendMessage(criticalHandle, Standard.WM.LBUTTONUP, IntPtr.Zero, IntPtr.Zero);
10021044
}
10031045

10041046
internal static void DoWindowTitleThumbChangeWindowStateOnMouseDoubleClick(MetroWindow window, MouseButtonEventArgs mouseButtonEventArgs)

MahApps.Metro/MahApps.Metro.nuspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package xmlns="http://schemas.microsoft.com/packaging/2011/10/nuspec.xsd">
33
<metadata>
44
<id>MahApps.Metro</id>
5-
<version>1.2.3.0</version>
5+
<version>1.2.4.0</version>
66
<title>MahApps.Metro</title>
77
<authors>Jan Karger, Dennis Daume, Brendan Forster, Paul Jenkins, Jake Ginnivan, Alex Mitchell</authors>
88
<owners>punker76,shiftkey,aeoth,jakeginnivan</owners>

MahApps.Metro/Properties/AssemblyInfo.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
[assembly: XmlnsDefinition("http://metro.mahapps.com/winfx/xaml/shared", "MahApps.Metro.Converters")]
1313
[assembly: XmlnsDefinition("http://metro.mahapps.com/winfx/xaml/controls", "MahApps.Metro.Controls")]
1414

15-
[assembly: AssemblyVersion("1.2.3.0")]
16-
[assembly: AssemblyFileVersion("1.2.3.0")]
17-
[assembly: AssemblyInformationalVersion("1.2.3.0")]
15+
[assembly: AssemblyVersion("1.2.4.0")]
16+
[assembly: AssemblyFileVersion("1.2.4.0")]
17+
[assembly: AssemblyInformationalVersion("1.2.4.0")]
1818
[assembly: AssemblyTitleAttribute("MahApps.Metro")]
1919
[assembly: AssemblyDescriptionAttribute("Toolkit for creating Metro styled WPF apps")]
20-
[assembly: AssemblyProductAttribute("MahApps.Metro 1.2.3")]
20+
[assembly: AssemblyProductAttribute("MahApps.Metro 1.2.4")]
2121
[assembly: AssemblyCompany("MahApps")]

MahApps.Metro/Themes/Flyout.xaml

+7-4
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,10 @@
233233
DockPanel.Dock="Bottom" />
234234
</DockPanel>
235235
</AdornerDecorator>
236-
<Thumb Style="{StaticResource WindowTitleThumbStyle}"
237-
Height="{Binding Path=TitlebarHeight, Mode=OneWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Controls:MetroWindow}}}"
238-
VerticalAlignment="Top"
239-
x:Name="PART_WindowTitleThumb" />
236+
<Controls:MetroThumb Style="{StaticResource WindowTitleThumbStyle}"
237+
Height="{Binding Path=TitlebarHeight, Mode=OneWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Controls:MetroWindow}}}"
238+
VerticalAlignment="Top"
239+
x:Name="PART_WindowTitleThumb" />
240240
</Grid>
241241
<ControlTemplate.Triggers>
242242
<DataTrigger Binding="{Binding Position, RelativeSource={RelativeSource Self}}"
@@ -256,6 +256,9 @@
256256
<Setter TargetName="PART_Content"
257257
Property="DockPanel.Dock"
258258
Value="Right" />
259+
<Setter TargetName="PART_WindowTitleThumb"
260+
Property="Visibility"
261+
Value="Collapsed" />
259262
</DataTrigger>
260263
</ControlTemplate.Triggers>
261264
</ControlTemplate>

MahApps.Metro/Themes/MetroWindow.xaml

+6
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,9 @@
224224
<Trigger Property="UseNoneWindowStyle" Value="True">
225225
<Setter TargetName="PART_WindowTitleThumb" Property="Grid.RowSpan" Value="2" />
226226
</Trigger>
227+
<Trigger Property="ShowTitleBar" Value="False">
228+
<Setter TargetName="PART_WindowTitleThumb" Property="Grid.RowSpan" Value="2" />
229+
</Trigger>
227230
<!-- handle active/inactive state -->
228231
<Trigger Property="IsActive"
229232
Value="False">
@@ -505,6 +508,9 @@
505508
<Trigger Property="UseNoneWindowStyle" Value="True">
506509
<Setter TargetName="PART_WindowTitleThumb" Property="Grid.RowSpan" Value="2" />
507510
</Trigger>
511+
<Trigger Property="ShowTitleBar" Value="False">
512+
<Setter TargetName="PART_WindowTitleThumb" Property="Grid.RowSpan" Value="2" />
513+
</Trigger>
508514
<!-- handle active/inactive state -->
509515
<Trigger Property="IsActive"
510516
Value="False">

docs/release-notes/1.2.4.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Notes
2+
3+
MahApps.Metro v1.2.4 bug fix release.
4+
5+
# Bugfixes
6+
7+
- #2288 First 30 units of flyout aren't clickable
8+
- #2324 DataGrid activated by Titlebar (rows are hovered while dragging a window over a DataGrid)
9+
- #2287 IsWindowDraggable broke starting in 1.2

0 commit comments

Comments
 (0)