diff --git a/nukebuild/Numerge b/nukebuild/Numerge
index 4464343aef..aef10ae67d 160000
--- a/nukebuild/Numerge
+++ b/nukebuild/Numerge
@@ -1 +1 @@
-Subproject commit 4464343aef5c8ab7a42fcb20a483a6058199f8b8
+Subproject commit aef10ae67dc55c95f49b52a505a0be33bfa297a5
diff --git a/src/Avalonia.Controls/Platform/InProcessDragSource.cs b/src/Avalonia.Controls/Platform/InProcessDragSource.cs
index f8ae9f4249..0918da1a90 100644
--- a/src/Avalonia.Controls/Platform/InProcessDragSource.cs
+++ b/src/Avalonia.Controls/Platform/InProcessDragSource.cs
@@ -147,7 +147,10 @@ namespace Avalonia.Platform
e.Handled = true;
}
else if (e.Key == Key.LeftCtrl || e.Key == Key.RightCtrl || e.Key == Key.LeftAlt || e.Key == Key.RightAlt)
- RaiseEventAndUpdateCursor(RawDragEventType.DragOver, _lastRoot, _lastPosition, e.Modifiers);
+ {
+ if (_lastRoot != null)
+ RaiseEventAndUpdateCursor(RawDragEventType.DragOver, _lastRoot, _lastPosition, e.Modifiers);
+ }
}
private void ProcessMouseEvents(RawMouseEventArgs e)
diff --git a/src/Avalonia.Controls/Window.cs b/src/Avalonia.Controls/Window.cs
index 437dad2693..01c9a3a110 100644
--- a/src/Avalonia.Controls/Window.cs
+++ b/src/Avalonia.Controls/Window.cs
@@ -371,8 +371,16 @@ namespace Avalonia.Controls
///
/// Shows the window.
///
+ ///
+ /// The window has already been closed.
+ ///
public override void Show()
{
+ if (PlatformImpl == null)
+ {
+ throw new InvalidOperationException("Cannot re-show a closed window.");
+ }
+
if (IsVisible)
{
return;
@@ -397,6 +405,9 @@ namespace Avalonia.Controls
/// Shows the window as a dialog.
///
/// The dialog's owner window.
+ ///
+ /// The window has already been closed.
+ ///
///
/// A task that can be used to track the lifetime of the dialog.
///
diff --git a/tests/Avalonia.Controls.UnitTests/WindowTests.cs b/tests/Avalonia.Controls.UnitTests/WindowTests.cs
index 8221dadc86..ee416c4cb0 100644
--- a/tests/Avalonia.Controls.UnitTests/WindowTests.cs
+++ b/tests/Avalonia.Controls.UnitTests/WindowTests.cs
@@ -292,6 +292,51 @@ namespace Avalonia.Controls.UnitTests
}
}
+ [Fact]
+ public void Calling_Show_On_Closed_Window_Should_Throw()
+ {
+ using (UnitTestApplication.Start(TestServices.StyledWindow))
+ {
+ var windowImpl = Mock.Of(x => x.Scaling == 1);
+ var target = new Window(windowImpl);
+
+ target.Show();
+ target.Close();
+
+ var openedRaised = false;
+ target.Opened += (s, e) => openedRaised = true;
+
+ var ex = Assert.Throws(() => target.Show());
+ Assert.Equal("Cannot re-show a closed window.", ex.Message);
+ Assert.False(openedRaised);
+ }
+ }
+
+ [Fact]
+ public async Task Calling_ShowDialog_On_Closed_Window_Should_Throw()
+ {
+ using (UnitTestApplication.Start(TestServices.StyledWindow))
+ {
+ var parent = new Mock();
+ var windowImpl = new Mock();
+ windowImpl.SetupProperty(x => x.Closed);
+ windowImpl.Setup(x => x.Scaling).Returns(1);
+
+ var target = new Window(windowImpl.Object);
+ var task = target.ShowDialog(parent.Object);
+
+ windowImpl.Object.Closed();
+ await task;
+
+ var openedRaised = false;
+ target.Opened += (s, e) => openedRaised = true;
+
+ var ex = await Assert.ThrowsAsync(() => target.ShowDialog(parent.Object));
+ Assert.Equal("Cannot re-show a closed window.", ex.Message);
+ Assert.False(openedRaised);
+ }
+ }
+
[Fact]
public void Window_Should_Be_Centered_When_WindowStartupLocation_Is_CenterScreen()
{