diff --git a/MahApps.Metro/Behaviours/BorderlessWindowBehavior.cs b/MahApps.Metro/Behaviours/BorderlessWindowBehavior.cs index ff350759df..2d750a7eaa 100644 --- a/MahApps.Metro/Behaviours/BorderlessWindowBehavior.cs +++ b/MahApps.Metro/Behaviours/BorderlessWindowBehavior.cs @@ -2,6 +2,7 @@ using System.Security; using System.Windows; using System.Windows.Controls; +using System.Windows.Controls.Primitives; using System.Windows.Interactivity; using System.Windows.Interop; using MahApps.Metro.Controls; @@ -340,6 +341,7 @@ private void AssociatedObject_Loaded(object sender, RoutedEventArgs e) window.SetIsHitTestVisibleInChromeProperty("PART_Icon"); window.SetIsHitTestVisibleInChromeProperty("PART_TitleBar"); + window.SetIsHitTestVisibleInChromeProperty("PART_WindowTitleThumb"); window.SetIsHitTestVisibleInChromeProperty("PART_LeftWindowCommands"); window.SetIsHitTestVisibleInChromeProperty("PART_RightWindowCommands"); window.SetIsHitTestVisibleInChromeProperty("PART_WindowButtonCommands"); diff --git a/MahApps.Metro/Controls/Flyout.cs b/MahApps.Metro/Controls/Flyout.cs index 6b64f761bf..a0824c5018 100644 --- a/MahApps.Metro/Controls/Flyout.cs +++ b/MahApps.Metro/Controls/Flyout.cs @@ -494,10 +494,12 @@ public override void OnApplyTemplate() if (this.windowTitleThumb != null) { + this.windowTitleThumb.PreviewMouseLeftButtonUp -= WindowTitleThumbOnPreviewMouseLeftButtonUp; this.windowTitleThumb.DragDelta -= this.WindowTitleThumbMoveOnDragDelta; this.windowTitleThumb.MouseDoubleClick -= this.WindowTitleThumbChangeWindowStateOnMouseDoubleClick; this.windowTitleThumb.MouseRightButtonUp -= this.WindowTitleThumbSystemMenuOnMouseRightButtonUp; + this.windowTitleThumb.PreviewMouseLeftButtonUp += WindowTitleThumbOnPreviewMouseLeftButtonUp; this.windowTitleThumb.DragDelta += this.WindowTitleThumbMoveOnDragDelta; this.windowTitleThumb.MouseDoubleClick += this.WindowTitleThumbChangeWindowStateOnMouseDoubleClick; this.windowTitleThumb.MouseRightButtonUp += this.WindowTitleThumbSystemMenuOnMouseRightButtonUp; @@ -520,6 +522,7 @@ protected internal void CleanUp(FlyoutsControl flyoutsControl) { if (this.windowTitleThumb != null) { + this.windowTitleThumb.PreviewMouseLeftButtonUp -= WindowTitleThumbOnPreviewMouseLeftButtonUp; this.windowTitleThumb.DragDelta -= this.WindowTitleThumbMoveOnDragDelta; this.windowTitleThumb.MouseDoubleClick -= this.WindowTitleThumbChangeWindowStateOnMouseDoubleClick; this.windowTitleThumb.MouseRightButtonUp -= this.WindowTitleThumbSystemMenuOnMouseRightButtonUp; @@ -527,6 +530,15 @@ protected internal void CleanUp(FlyoutsControl flyoutsControl) this.parentWindow = null; } + private void WindowTitleThumbOnPreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e) + { + var window = this.ParentWindow; + if (window != null && this.Position != Position.Bottom) + { + MetroWindow.DoWindowTitleThumbOnPreviewMouseLeftButtonUp(window, e); + } + } + private void WindowTitleThumbMoveOnDragDelta(object sender, DragDeltaEventArgs dragDeltaEventArgs) { var window = this.ParentWindow; diff --git a/MahApps.Metro/Controls/MetroWindow.cs b/MahApps.Metro/Controls/MetroWindow.cs index 3846d2b8b6..25e32a2119 100644 --- a/MahApps.Metro/Controls/MetroWindow.cs +++ b/MahApps.Metro/Controls/MetroWindow.cs @@ -10,7 +10,9 @@ using MahApps.Metro.Native; using System.Windows.Shapes; using System.Collections.Generic; +using System.Reflection; using System.Windows.Controls.Primitives; +using System.Windows.Threading; namespace MahApps.Metro.Controls { @@ -899,11 +901,23 @@ public override void OnApplyTemplate() this.SetVisibiltyForAllTitleElements(this.TitlebarHeight > 0); } + protected IntPtr CriticalHandle + { + get + { + var value = typeof(Window) + .GetProperty("CriticalHandle", BindingFlags.NonPublic | BindingFlags.Instance) + .GetValue(this, new object[0]); + return (IntPtr)value; + } + } + private void ClearWindowEvents() { // clear all event handlers first: if (this.windowTitleThumb != null) { + this.windowTitleThumb.PreviewMouseLeftButtonUp -= WindowTitleThumbOnPreviewMouseLeftButtonUp; this.windowTitleThumb.DragDelta -= this.WindowTitleThumbMoveOnDragDelta; this.windowTitleThumb.MouseDoubleClick -= this.WindowTitleThumbChangeWindowStateOnMouseDoubleClick; this.windowTitleThumb.MouseRightButtonUp -= this.WindowTitleThumbSystemMenuOnMouseRightButtonUp; @@ -928,6 +942,7 @@ private void SetWindowEvents() if (this.windowTitleThumb != null) { + this.windowTitleThumb.PreviewMouseLeftButtonUp += WindowTitleThumbOnPreviewMouseLeftButtonUp; this.windowTitleThumb.DragDelta += this.WindowTitleThumbMoveOnDragDelta; this.windowTitleThumb.MouseDoubleClick += this.WindowTitleThumbChangeWindowStateOnMouseDoubleClick; this.windowTitleThumb.MouseRightButtonUp += this.WindowTitleThumbSystemMenuOnMouseRightButtonUp; @@ -955,6 +970,11 @@ private void IconMouseDown(object sender, MouseButtonEventArgs e) } } + private void WindowTitleThumbOnPreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e) + { + DoWindowTitleThumbOnPreviewMouseLeftButtonUp(this, e); + } + private void WindowTitleThumbMoveOnDragDelta(object sender, DragDeltaEventArgs dragDeltaEventArgs) { DoWindowTitleThumbMoveOnDragDelta(this, dragDeltaEventArgs); @@ -970,18 +990,24 @@ private void WindowTitleThumbSystemMenuOnMouseRightButtonUp(object sender, Mouse DoWindowTitleThumbSystemMenuOnMouseRightButtonUp(this, e); } + internal static void DoWindowTitleThumbOnPreviewMouseLeftButtonUp(MetroWindow window, MouseButtonEventArgs mouseButtonEventArgs) + { + Mouse.Capture(null); + } + internal static void DoWindowTitleThumbMoveOnDragDelta(MetroWindow window, DragDeltaEventArgs dragDeltaEventArgs) { // drag only if IsWindowDraggable is set to true if (!window.IsWindowDraggable || - (!(Math.Abs(dragDeltaEventArgs.HorizontalChange) > 2) && - !(Math.Abs(dragDeltaEventArgs.VerticalChange) > 2))) return; + (!(Math.Abs(dragDeltaEventArgs.HorizontalChange) > 2) && !(Math.Abs(dragDeltaEventArgs.VerticalChange) > 2))) + { + return; + } - var windowHandle = new WindowInteropHelper(window).Handle; - var cursorPos = Standard.NativeMethods.GetCursorPos(); + // tage from DragMove internal code + window.VerifyAccess(); - // for the touch usage - UnsafeNativeMethods.ReleaseCapture(); + var cursorPos = Standard.NativeMethods.GetCursorPos(); // if the window is maximized dragging is only allowed on title bar (also if not visible) var windowIsMaximized = window.WindowState == WindowState.Maximized; @@ -991,14 +1017,30 @@ internal static void DoWindowTitleThumbMoveOnDragDelta(MetroWindow window, DragD return; } - if (windowIsMaximized) - { + // for the touch usage + UnsafeNativeMethods.ReleaseCapture(); + + if (windowIsMaximized) { window.Top = 2; window.Left = Math.Max(cursorPos.x - window.RestoreBounds.Width / 2, 0); + EventHandler windowOnStateChanged = null; + windowOnStateChanged = (sender, args) => + { + window.StateChanged -= windowOnStateChanged; + if (window.WindowState == WindowState.Normal) + { + Mouse.Capture(window.windowTitleThumb, CaptureMode.Element); + } + }; + window.StateChanged += windowOnStateChanged; } - var lParam = (int)(uint)cursorPos.x | (cursorPos.y << 16); - Standard.NativeMethods.SendMessage(windowHandle, Standard.WM.LBUTTONUP, (IntPtr)Standard.HT.CAPTION, (IntPtr)lParam); - Standard.NativeMethods.SendMessage(windowHandle, Standard.WM.SYSCOMMAND, (IntPtr)Standard.SC.MOUSEMOVE, IntPtr.Zero); + + var criticalHandle = window.CriticalHandle; + // DragMove works too + // window.DragMove(); + // instead this 2 lines + Standard.NativeMethods.SendMessage(criticalHandle, Standard.WM.SYSCOMMAND, (IntPtr)Standard.SC.MOUSEMOVE, IntPtr.Zero); + Standard.NativeMethods.SendMessage(criticalHandle, Standard.WM.LBUTTONUP, IntPtr.Zero, IntPtr.Zero); } internal static void DoWindowTitleThumbChangeWindowStateOnMouseDoubleClick(MetroWindow window, MouseButtonEventArgs mouseButtonEventArgs) diff --git a/MahApps.Metro/MahApps.Metro.nuspec b/MahApps.Metro/MahApps.Metro.nuspec index 5b4597254b..afe33b0bd4 100644 --- a/MahApps.Metro/MahApps.Metro.nuspec +++ b/MahApps.Metro/MahApps.Metro.nuspec @@ -2,7 +2,7 @@ MahApps.Metro - 1.2.3.0 + 1.2.4.0 MahApps.Metro Jan Karger, Dennis Daume, Brendan Forster, Paul Jenkins, Jake Ginnivan, Alex Mitchell punker76,shiftkey,aeoth,jakeginnivan diff --git a/MahApps.Metro/Properties/AssemblyInfo.cs b/MahApps.Metro/Properties/AssemblyInfo.cs index 8d61b35fd0..7d7ca78e09 100644 --- a/MahApps.Metro/Properties/AssemblyInfo.cs +++ b/MahApps.Metro/Properties/AssemblyInfo.cs @@ -12,10 +12,10 @@ [assembly: XmlnsDefinition("http://metro.mahapps.com/winfx/xaml/shared", "MahApps.Metro.Converters")] [assembly: XmlnsDefinition("http://metro.mahapps.com/winfx/xaml/controls", "MahApps.Metro.Controls")] -[assembly: AssemblyVersion("1.2.3.0")] -[assembly: AssemblyFileVersion("1.2.3.0")] -[assembly: AssemblyInformationalVersion("1.2.3.0")] +[assembly: AssemblyVersion("1.2.4.0")] +[assembly: AssemblyFileVersion("1.2.4.0")] +[assembly: AssemblyInformationalVersion("1.2.4.0")] [assembly: AssemblyTitleAttribute("MahApps.Metro")] [assembly: AssemblyDescriptionAttribute("Toolkit for creating Metro styled WPF apps")] -[assembly: AssemblyProductAttribute("MahApps.Metro 1.2.3")] +[assembly: AssemblyProductAttribute("MahApps.Metro 1.2.4")] [assembly: AssemblyCompany("MahApps")] diff --git a/MahApps.Metro/Themes/Flyout.xaml b/MahApps.Metro/Themes/Flyout.xaml index c55a94c961..15ea7d4bbe 100644 --- a/MahApps.Metro/Themes/Flyout.xaml +++ b/MahApps.Metro/Themes/Flyout.xaml @@ -233,10 +233,10 @@ DockPanel.Dock="Bottom" /> - + + diff --git a/MahApps.Metro/Themes/MetroWindow.xaml b/MahApps.Metro/Themes/MetroWindow.xaml index 23bf931bbf..8397c33342 100644 --- a/MahApps.Metro/Themes/MetroWindow.xaml +++ b/MahApps.Metro/Themes/MetroWindow.xaml @@ -224,6 +224,9 @@ + + + @@ -505,6 +508,9 @@ + + + diff --git a/docs/release-notes/1.2.4.md b/docs/release-notes/1.2.4.md new file mode 100644 index 0000000000..ec6576a978 --- /dev/null +++ b/docs/release-notes/1.2.4.md @@ -0,0 +1,9 @@ +# Notes + +MahApps.Metro v1.2.4 bug fix release. + +# Bugfixes + +- #2288 First 30 units of flyout aren't clickable +- #2324 DataGrid activated by Titlebar (rows are hovered while dragging a window over a DataGrid) +- #2287 IsWindowDraggable broke starting in 1.2