Skip to content

Commit 8d2220d

Browse files
authored
Merge pull request #4555 from MahApps/fix/4554-window-not-movable
Use WindowInteropHelper to get the window handle
2 parents e4bb760 + 1814d54 commit 8d2220d

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

src/MahApps.Metro/Controls/MetroWindow.cs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using System.ComponentModel;
99
using System.Diagnostics.CodeAnalysis;
1010
using System.Linq;
11-
using System.Reflection;
1211
using System.Windows;
1312
using System.Windows.Automation;
1413
using System.Windows.Automation.Peers;
@@ -18,6 +17,7 @@
1817
using System.Windows.Media.Animation;
1918
using System.Windows.Shapes;
2019
using System.Windows.Controls.Primitives;
20+
using System.Windows.Interop;
2121
using Windows.Win32;
2222
using Windows.Win32.Foundation;
2323
using ControlzEx;
@@ -220,7 +220,7 @@ public static readonly DependencyProperty ShowFlyoutsOverDialogsProperty
220220
if (d is MetroWindow window && window.Flyouts != null)
221221
{
222222
// It's not allowed to change this if any Flyout is open
223-
// TODO Find a way to reset the zIndex of any open Flyout if <see cref="ShowFlyoutsOverDialogs"/> is changed by the user
223+
// TODO Find a way to reset the zIndex of any open Flyout if <see cref="ShowFlyoutsOverDialogs"/> is changed by the user
224224
var anyFlyoutOpen = window.Flyouts.GetFlyouts().Any(f => f.IsOpen);
225225
if (anyFlyoutOpen)
226226
{
@@ -1457,16 +1457,6 @@ protected override AutomationPeer OnCreateAutomationPeer()
14571457
return new MetroWindowAutomationPeer(this);
14581458
}
14591459

1460-
protected internal IntPtr CriticalHandle
1461-
{
1462-
get
1463-
{
1464-
this.VerifyAccess();
1465-
var value = typeof(Window).GetProperty("CriticalHandle", BindingFlags.NonPublic | BindingFlags.Instance)?.GetValue(this, new object[0]) ?? IntPtr.Zero;
1466-
return (IntPtr)value;
1467-
}
1468-
}
1469-
14701460
private void ClearWindowEvents()
14711461
{
14721462
if (this.windowTitleThumb != null)
@@ -1642,7 +1632,8 @@ internal static void DoWindowTitleThumbMoveOnDragDelta(IMetroThumb? thumb, Metro
16421632
var wpfPoint = window.PointToScreen(Mouse.GetPosition(window));
16431633
var x = (int)wpfPoint.X;
16441634
var y = (int)wpfPoint.Y;
1645-
PInvoke.SendMessage(new HWND(window.CriticalHandle), PInvoke.WM_NCLBUTTONDOWN, new WPARAM((nuint)HT.CAPTION), new IntPtr(x | (y << 16)));
1635+
var windowHandle = new WindowInteropHelper(window).EnsureHandle();
1636+
PInvoke.SendMessage(new HWND(windowHandle), PInvoke.WM_NCLBUTTONDOWN, new WPARAM((nuint)HT.CAPTION), new IntPtr(x | (y << 16)));
16461637
}
16471638

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

0 commit comments

Comments
 (0)