Skip to content

Commit c32846a

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

File tree

2 files changed

+11
-21
lines changed

2 files changed

+11
-21
lines changed

appveyor.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,24 @@ branches:
44
only:
55
- develop
66
- main
7+
- /v\d*\.\d*\.\d*/
78

89
environment:
10+
# bad, but without this, gitversion doesn't work anymore
911
IGNORE_NORMALISATION_GIT_HEAD_MOVE: 1
1012
azure-key-vault-url:
1113
secure: 1mKS/HfCVq+iYNRVSrrN8NEowOkKt3knrpMzw+SOy3g=
1214
azure-key-vault-client-id:
1315
secure: JfSqzmsJdXB6uIxttCRoQw1NygwxqXHDj9uIqQnWOb9VCnQYlRPlAnxgW0yTSX4b
16+
azure-key-vault-tenant-id:
17+
secure: FxjkcqtpulfpDpfSAu4onaLVP/H1S1ORRCQCqsZkDC6YhCSmFoMxYNsWv5uGe3ah
1418
azure-key-vault-client-secret:
1519
secure: CUpRJxMLeUZwNPMcqI0wECaWfy5AMnWn1UZhBd9WnQ3Z16lJP1Vzrkf24mccbhUD
1620
azure-key-vault-certificate:
1721
secure: BSPdW2TgnQtoQXXbeDECug==
1822

19-
skip_tags: true
20-
image: Visual Studio 2019
21-
test: off
22-
23-
install:
24-
#- cinst dotnetcore-sdk --version=3.1.100
23+
image: Visual Studio 2022
24+
test: false
2525

2626
pull_requests:
2727
do_not_increment_build_number: false
@@ -40,4 +40,4 @@ nuget:
4040

4141
skip_commits:
4242
files:
43-
- '**/*.md'
43+
- '**/*.md'

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)