Browse Source
Merge pull request #1726 from jp2masa/window-closing-fix
Fixed Window.Close, so that Closing is only invoked once
pull/1721/merge
Jeremy Koritzinsky
8 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
28 additions and
7 deletions
-
src/Avalonia.Controls/Window.cs
-
tests/Avalonia.Controls.UnitTests/WindowTests.cs
|
|
@ -302,18 +302,17 @@ namespace Avalonia.Controls |
|
|
|
|
|
|
|
|
internal void Close(bool ignoreCancel) |
|
|
internal void Close(bool ignoreCancel) |
|
|
{ |
|
|
{ |
|
|
var cancelClosing = false; |
|
|
|
|
|
try |
|
|
try |
|
|
{ |
|
|
{ |
|
|
cancelClosing = HandleClosing(); |
|
|
if (!ignoreCancel && HandleClosing()) |
|
|
|
|
|
{ |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
finally |
|
|
finally |
|
|
{ |
|
|
{ |
|
|
if (ignoreCancel || !cancelClosing) |
|
|
PlatformImpl?.Dispose(); |
|
|
{ |
|
|
HandleClosed(); |
|
|
PlatformImpl?.Dispose(); |
|
|
|
|
|
HandleClosed(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -324,6 +323,7 @@ namespace Avalonia.Controls |
|
|
{ |
|
|
{ |
|
|
var args = new CancelEventArgs(); |
|
|
var args = new CancelEventArgs(); |
|
|
Closing?.Invoke(this, args); |
|
|
Closing?.Invoke(this, args); |
|
|
|
|
|
|
|
|
return args.Cancel; |
|
|
return args.Cancel; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -188,6 +188,27 @@ namespace Avalonia.Controls.UnitTests |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[Fact] |
|
|
|
|
|
public void Closing_Should_Only_Be_Invoked_Once() |
|
|
|
|
|
{ |
|
|
|
|
|
using (UnitTestApplication.Start(TestServices.StyledWindow)) |
|
|
|
|
|
{ |
|
|
|
|
|
var window = new Window(); |
|
|
|
|
|
var count = 0; |
|
|
|
|
|
|
|
|
|
|
|
window.Closing += |
|
|
|
|
|
(sender, e) => |
|
|
|
|
|
{ |
|
|
|
|
|
count++; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
window.Show(); |
|
|
|
|
|
window.Close(); |
|
|
|
|
|
|
|
|
|
|
|
Assert.Equal(1, count); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
public void Showing_Should_Start_Renderer() |
|
|
public void Showing_Should_Start_Renderer() |
|
|
{ |
|
|
{ |
|
|
|