-
-
Notifications
You must be signed in to change notification settings - Fork 76
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
IDialogService.Close manage a boolean return type such as IDialogServ… #116
Conversation
…ice.Activate method.
I'm currently on a mini-vacation and will be back on Saturday. I'll look more closely at the PR then, but from a glance I think we should cover this use-case with tests. |
The current behavior is to throw an exception when closing a dialog fails, and with your changes the behavior will be that a boolean is returned indicating whether the operation was successful or not. Both behaviors convey whether the operation was successful or not, am I correct in that statement? I'm here scratching my head thinking I'm missing something, but then again it's early morning here in Sweden and my brain is in startup mode. With your changes, what do we gain other than that the caller can use |
Hello Mattias,
thanks for your fast feedback, I hope you are experiencing a nice vacation.
Well, as you told me both behaviors seem to have the same result, you finally know if the closing operation was successful or not, but “raise and catch” an exception is a more heavy operation then “if then else” or “ ? : ”.
I think the real question is: why use an exception to communicate a boolean result? And why only in the Close method and not also in the Activate method?
Please let me try to summarize and explain what we could gain by my approach:
1) By the second behavior you’ll have the same approach in both Activate and Close methods.
2) Depending on the dialog opening logic, you couldn’t know if the opened dialog is modal or not. By the second behavior you can simply close it by calling both DialogResult = xxx; and then DialogService.Close(VMInstance); without worrying about dialog’s opening mode and without using a try-catch block.
3) In the actual behavior the “DialogNotFoundException” is not the only one exception that the Close method could raise: think about some WPF error. So, in a try-catch block you must consider the exception type.
4) By the actual behavior, in some particular case, using a try-catch block is not “quick” for a developer.
5) By the second behavior, if you are not interested in Close result, you can always call Close(VMInstance) without using an empty catch or without using the Activate method before, to know if the dialog is still alive..
Because my english (I know) is not fluent, to clarify what I mean please let me add some code snippets.
Consider the following showing logic:
![code-snippet1](https://user-images.githubusercontent.com/10128151/89645093-67307600-d8b9-11ea-879a-00c0586b22ae.jpg)
Now, in the actual behavior, if you wanna close the dialog from its viewmodel you must do:
![code-snippet2](https://user-images.githubusercontent.com/10128151/89645111-71527480-d8b9-11ea-8092-d31c58940d54.jpg)
Or, if you don’t like to use a try catch block for that operation:
![code-snippet3](https://user-images.githubusercontent.com/10128151/89645169-8b8c5280-d8b9-11ea-8da9-36e725e62dc4.jpg)
(the screenshot above is the actual scenario used in my current project but, when the dialog is in "non modal mode" and not "on top", we have a flashing to top effect before its closure)
By my behavior you could do:
![code-snippet4](https://user-images.githubusercontent.com/10128151/89645200-9cd55f00-d8b9-11ea-87c6-263c2bd871ef.jpg)
In a shorter logic, by the actual approach you must do:
![code-snippet5](https://user-images.githubusercontent.com/10128151/89645237-a8288a80-d8b9-11ea-9a08-054381e983af.jpg)
By my approach you could do:
![code-snippet6](https://user-images.githubusercontent.com/10128151/89645272-b8406a00-d8b9-11ea-97e8-b6c11e953ace.jpg)
Anyway, if you prefer, you could also consider to add my behavior as an overloading of Close method.
I hope you'll find my thought clear.
Thanks for your time and please keep me in touch.
Best Regards,
Roberto.
|
Your argument is sound, having a parity between
|
BTW, your English is perfect, you should not apologize for it. |
Hi Mattias, Thanks for your availability and see you soon. Regards, Roberto. |
I'll prepare the code for the release, but I have to do one other thing first. I'm estimating that we'll have a release for you later this week. |
Perfect Mattias, take your time, there's no hurry.. |
@rogiardi v8.0.0-beta.1 has now been published on www.nuget.org. Would you be able to update and see if the changes are according to your requirements? |
IDialogService.Close returns false instead of throwing an exception when failing to close a dialog. This behavior aligns with the behavior of IDialogService.Activate.
IDialogService.Close returns false instead of throwing an exception when failing to close a dialog. This behavior aligns with the behavior of IDialogService.Activate.
IDialogService.Close returns false instead of throwing an exception when failing to close a dialog. This behavior aligns with the behavior of IDialogService.Activate.
Hi Mattias, Thanks, Roberto. |
IDialogService.Close returns false instead of throwing an exception when failing to close a dialog. This behavior aligns with the behavior of IDialogService.Activate.
IDialogService.Close returns false instead of throwing an exception when failing to close a dialog. This behavior aligns with the behavior of IDialogService.Activate.
IDialogService.Close returns false instead of throwing an exception when failing to close a dialog. This behavior aligns with the behavior of IDialogService.Activate.
IDialogService.Close returns false instead of throwing an exception when failing to close a dialog. This behavior aligns with the behavior of IDialogService.Activate.
IDialogService.Close returns false instead of throwing an exception when failing to close a dialog. This behavior aligns with the behavior of IDialogService.Activate.
* feat: IDialogService.Close returns boolean indicating success (#116) IDialogService.Close returns false instead of throwing an exception when failing to close a dialog. This behavior aligns with the behavior of IDialogService.Activate. * release v8.0.0-beta.1 * release v8.0.0-beta.2 * release v8.0.0-beta.3 * release v8.0.0-beta.4 * chore: update assembly version Co-authored-by: Roberto Giardi <roberto.giardi@eng.it>
…ice.Activate method.
Description
In case Show or ShowModal are based on certain logic, you cannot know if the window is modal or not. If you also need to close the window from its ViewModel, you can call .Close(this) without worrying about possible exceptions.
To check if window has been found and correctly closed, you can test the boolean result
Checklist