-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ClosingBehavior api to Window #14621
Conversation
fbc8ecb
to
603ac32
Compare
You can test this PR using the following package version. |
/// <summary> | ||
/// When the owner window is closed, the child windows' <see cref="Window.Closing"/> event | ||
/// will be raised, followed by the owner window's <see cref="Window.Closing"/> events. A child | ||
/// canceling the close will result in the owner Window's close being cancelled. | ||
/// </summary> | ||
OwnerAndChildWindows, | ||
|
||
/// <summary> | ||
/// When the owner window is closed, only the owner window's <see cref="Window.Closing"/> event | ||
/// will be raised. This behavior is the same as WPF's. | ||
/// </summary> | ||
OwnerWindowOnly, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the Closing
and Closed
events are a bit mixed in the XML comments, at least for OwnerAndChildWindows
. According to the PR description, it doesn't raise the Closing
event for child windows. Is that right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When set to OwnerAndChildWindows
which is the default and is the current behavior as of master, Closing
will be raised on all child windows before being raised on the parent. Closed
event is raised at the point that it's decided the window will be closed, i.e. all Closing
handlers that were raised didn't cancel Closing
event.
Out of curiosity, when does |
|
I think this is the confusing part of the PR description:
This is supposed to mean that the |
I've updated to "skipping raising the |
In that case, I think the XML documentation is wrong, because the /// When the owner window is closed, the child windows' <see cref="Window.Closing"/> event
/// will be raised, followed by the owner window's <see cref="Window.Closing"/> events. A child
/// canceling the close will result in the owner Window's close being cancelled. |
The description is accurate. |
You're right. I was confused... Sorry for wasting your time, and thanks for clarifying. |
What does the pull request do?
Adds the following api to the Window class;
What is the current behavior?
Avalonia's Window closing order when child windows are present differs from WPF's and can cause some side effects when there are many child windows to managed. All child windows are checked for closing before the parent window gets checked. If a child window performs disposal logic or any logic that may change the state of the window, assuming that it's going to get closed, but the Closing event is cancelled by the next child or the parent window, that window may be left in an invalid state.
What is the updated/expected behavior with this PR?
This pr add api to decide how closing multiple related windows should be handled. if
ClosingBehavior
is set toOwnerWindowOnly
, only the owner window, i.e the window where the Closing event was first raised either by the Close button or programmatically, checks for cancellation, and if not cancelled, all child windows are Closed, skipping raising the Closing event for child windows. SettingClosingBehavior
toOwnerAndChildWindows
, which is the default, maintains the previous behavior.How was the solution implemented (if it's not obvious)?
Checklist
Breaking changes
Obsoletions / Deprecations
Fixed issues