MahApps / MahApps/MahApps.Metro
Should MessageDialog's CancellationToken honour DialogResultOnCancel like Escape does?
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 9.8k
- Forks
- 2.4k
- Avg merge
- 1h 2m
- Merged PRs (30d)
- 56
Description
A MessageDialog can end without a button press in two ways, and the two disagree about what to return.
In MessageDialog.WaitForButtonPressAsync, pressing Esc or Alt+F4 honours the setting:
tcs.TrySetResult(this.DialogSettings.DialogResultOnCancel
?? (this.ButtonStyle == MessageDialogStyle.Affirmative
? MessageDialogResult.Affirmative
: MessageDialogResult.Negative));
Cancelling MetroDialogSettings.CancellationToken does not:
tcs.TrySetResult(this.ButtonStyle == MessageDialogStyle.Affirmative
? MessageDialogResult.Affirmative
: MessageDialogResult.Negative);
So a caller who sets DialogResultOnCancel = MessageDialogResult.FirstAuxiliary for a Save / Discard / Cancel dialog gets FirstAuxiliary from the keyboard but Negative from the token.
Not a regression
DialogResultOnCancel came in with ebee93f8 for #2619, and that request was explicitly about the keyboard:
allow the caller to select the default "Escape" / cancel action
So the narrow scope was deliberate at the time, and the token path was simply never part of it. Raising this as a question rather than a bug report for that reason.
Why it still seems worth aligning
- The property is named
DialogResultOnCancel, notDialogResultOnEscape. Firing aCancellationTokenis about as literal a cancel as there is, so the current split is surprising. MessageDialogcontradicts itself: two code paths that both mean "closed without a button press" produce different values.- The other dialogs do not have the split. In
InputDialogthe token, Esc and the Cancel button all resolve tonull;MessageDialogis the odd one out.
Options
Align — have the token path use the same DialogResultOnCancel ?? (…) expression as the keyboard path. One line.
It is still a behavioural change, so it belongs in a minor release with a note. The blast radius looks small: only callers who both set DialogResultOnCancel and cancel through the token are affected, and for them the new value is very likely the one they were already expecting.
Or clarify — if the behaviour should stay as it is, the property's XML comment could say that it applies to the keyboard only. The name on its own suggests otherwise, and nothing in IntelliSense corrects that impression today.
Either way the current behaviour is now described on the message dialog docs page.
Environment
MahApps.Metro version: v2.4.11 (and develop)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in MessageDialog.WaitForButtonPressAsync and compare the CancellationToken path with the Escape/Alt+F4 path, using the issue's examples to understand the differing results. Decide whether cancellation should honor DialogResultOnCancel or whether the property's XML documentation should limit its scope; done means the chosen behavior is consistent and the message-dialog documentation or release note reflects it.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- desktop
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100