Skip to content

Commit f1e91f8

Browse files
committed
Merge pull request #4555 from MahApps/fix/4554-window-not-movable
Use WindowInteropHelper to get the window handle
1 parent 4cd550c commit f1e91f8

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

src/MahApps.Metro/Controls/MetroWindow.cs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

@@ -7,7 +7,6 @@
77
using System.Collections.Generic;
88
using System.ComponentModel;
99
using System.Linq;
10-
using System.Reflection;
1110
using System.Windows;
1211
using System.Windows.Automation;
1312
using System.Windows.Automation.Peers;
@@ -18,6 +17,7 @@
1817
using System.Windows.Shapes;
1918
using System.Windows.Controls.Primitives;
2019
using System.Windows.Data;
20+
using System.Windows.Interop;
2121
using ControlzEx.Behaviors;
2222
using ControlzEx.Native;
2323
using ControlzEx.Standard;
@@ -1279,16 +1279,6 @@ protected override AutomationPeer OnCreateAutomationPeer()
12791279
return new MetroWindowAutomationPeer(this);
12801280
}
12811281

1282-
protected internal IntPtr CriticalHandle
1283-
{
1284-
get
1285-
{
1286-
this.VerifyAccess();
1287-
var value = typeof(Window).GetProperty("CriticalHandle", BindingFlags.NonPublic | BindingFlags.Instance)?.GetValue(this, new object[0]) ?? IntPtr.Zero;
1288-
return (IntPtr)value;
1289-
}
1290-
}
1291-
12921282
private void ClearWindowEvents()
12931283
{
12941284
// clear all event handlers first:
@@ -1470,7 +1460,6 @@ internal static void DoWindowTitleThumbMoveOnDragDelta(IMetroThumb thumb, [NotNu
14701460
window.StateChanged += windowOnStateChanged;
14711461
}
14721462

1473-
var criticalHandle = window.CriticalHandle;
14741463
#pragma warning disable 618
14751464
// these lines are from DragMove
14761465
// NativeMethods.SendMessage(criticalHandle, WM.SYSCOMMAND, (IntPtr)SC.MOUSEMOVE, IntPtr.Zero);
@@ -1479,7 +1468,8 @@ internal static void DoWindowTitleThumbMoveOnDragDelta(IMetroThumb thumb, [NotNu
14791468
var wpfPoint = window.PointToScreen(Mouse.GetPosition(window));
14801469
var x = (int)wpfPoint.X;
14811470
var y = (int)wpfPoint.Y;
1482-
NativeMethods.SendMessage(criticalHandle, WM.NCLBUTTONDOWN, (IntPtr)HT.CAPTION, new IntPtr(x | (y << 16)));
1471+
var windowHandle = new WindowInteropHelper(window).EnsureHandle();
1472+
NativeMethods.SendMessage(windowHandle, WM.NCLBUTTONDOWN, (IntPtr)HT.CAPTION, new IntPtr(x | (y << 16)));
14831473
#pragma warning restore 618
14841474
}
14851475

0 commit comments

Comments
 (0)