Skip to content

Commit e169907

Browse files
author
danwalmsley
authored
Merge pull request #3306 from AvaloniaUI/fixes/double-detach-window-issue
Fix Exception when window is closed via Close() Method
2 parents 531b70f + b8b8e3f commit e169907

3 files changed

Lines changed: 5 additions & 3 deletions

File tree

src/Avalonia.Controls/Window.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,6 @@ internal void Close(bool ignoreCancel)
336336
if (close)
337337
{
338338
PlatformImpl?.Dispose();
339-
HandleClosed();
340339
}
341340
}
342341
}

tests/Avalonia.Controls.UnitTests/WindowTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,7 @@ public void Calling_Show_On_Closed_Window_Should_Throw()
228228
{
229229
using (UnitTestApplication.Start(TestServices.StyledWindow))
230230
{
231-
var windowImpl = Mock.Of<IWindowImpl>(x => x.Scaling == 1);
232-
var target = new Window(windowImpl);
231+
var target = new Window();
233232

234233
target.Show();
235234
target.Close();

tests/Avalonia.UnitTests/MockWindowingPlatform.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ public static Mock<IWindowImpl> CreateWindowMock(Func<IPopupImpl> popupImpl = nu
2828
return CreatePopupMock().Object;
2929

3030
});
31+
mock.Setup(x => x.Dispose()).Callback(() =>
32+
{
33+
mock.Object.Closed?.Invoke();
34+
});
3135
PixelPoint pos = default;
3236
mock.SetupGet(x => x.Position).Returns(() => pos);
3337
mock.Setup(x => x.Move(It.IsAny<PixelPoint>())).Callback(new Action<PixelPoint>(np => pos = np));

0 commit comments

Comments
 (0)