-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[WPF] New IDialogService #1682
[WPF] New IDialogService #1682
Conversation
@brianlagunas There is small type in Create Your Dialog View Code. CommandPrameter="true" |
@LGTCO Why you are passing the DialogWindow name as uri. DialogWindow is just the container in which your view will be injected. You must be passing the view which you want to inject inside the DialogWindow. |
Thank you!I get it |
Is it possible to pass more than one parameter? |
Nevermind.
|
Wonder why these two methods
don't have async interface like this
|
@ekalchev dialogs in WPF are not async |
For completeness await this.ShowMessageAsync("This is the title", "Some message"); |
Those aren't doing what you think they're doing. In fact, that entire API is useless as there is only one UI thread in WPF, so using the dispatcher to provide an "async" API but not an async behavior is pointless. Also, those dialogs are UI blocking (think MessageBox.ShowDialog). In Prism the dialogs can live on, be interacted with, and multiple more opened while the main application is also interacted with. |
I agree with your point of view and I don't use Dialog asynchronously myself. |
Agree to disagree. I wish async/await was never invented. At least with the old school async API's, people had to actually understand how things worked when multi-threading 😄 |
Totally agree. I wouldn't want to be off topic, but: |
So why bother to a have callback if you writing interface for blocking call for ShowDialog method?
What about Show method, it is non blocking? Callback style programming is in the past.
async doens't mean multithreaded programming. Async programming is perfectly legal with only one thread and javascript do that for decades. https://blogs.msdn.microsoft.com/benwilli/2015/09/10/tasks-are-still-not-threads-and-async-is-not-parallel/ I can give you more examples like this https://github.com/lbugnion/mvvmlight/blob/master/GalaSoft.MvvmLight/GalaSoft.MvvmLight.Platform%20(UWP)/Views/DialogService.cs |
@ekalchev There are many reason why the API's are the way they are. A big one is making it easy to extend (replace windows with other window types) with little to no code requirements. Another reason is I wanted to method signature to be the same. A Show is non-block and may never be close, but when it does close you still want to be notified. A ShowDialog is blocking and could have returned the IDialogResult directly, but I didn't want to introduce custom methods on the Window Class, and I wanted the APIs for both methods to be the same so the developer experience is consistent. You are more than welcome to create your own async dialog interfaces in your apps, but I will not be adding them to Prism as there is no real benefit beside syntactical sugar. |
If you want an public static void Task<IDialogResult> ShowDialog( this IDialogService dialogService, string name)
{
var tcs = new TaskCompletionSource<IDialogResult>();
dialogService.ShowDialog(name, result => tcs.SetResult(result));
return tcs.Task;
} |
Like I said, syntactical sugar 😄 |
Is there any way for the DialogService to show a dialog that is modal for a single view in WPF? I've got a tabbed application where it can prompt the user in one view (locking that whole view/tab) but they can tab to another view to check other data etc. then return and respond to the dialog. Currently I use InteractionRequestTriggers that add the dialog templates as children to the AssociatedObject (as per the original guidance when I started using it 6 or 7 years ago). I know you plan on removing PopupWindowAction (which I don't use) but I've noticed that all the InteractionRequest classes are marked as obsolete as well. So if there is a way in DialogService to make the dialogs modal locally within the view then I'll happily change everything to use it. Thanks, |
That's not how the PopupWindowAction works. The PopupWindowAction shows an actual Window (Window.ShowDialog) which is not capable of blocking a single tab in a tabbed page. For that scenario you must use a different approach which mimics a Window (but is not actually a Window) and can scope it's behavior to the current Tab. The only thing the PopupWIndowAction does is show a Window. The same thing the new DialogService does. PopupWindowAction will be going away. If you feel you need it, grab the code and bring it into your app. |
Hi Brian, Yep, I understand PopupWindowAction shows an actual window (which is why I don't use it). Thanks |
Hi! Thanks & best regards! |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Currently, the only way to show any type of dialog with Prism is by using the PopupWindowAction in combination with
System.Windows.Interactivity
. To be honest, I really dislike this approach. It's over complex, highly verbose, difficult to implement, and is very limited. The limitations are covered pretty well in Issue #864Instead, I created a new
IDialogService
API that will replace the PopupWindowAction altogether. This service will allow developers to show any dialog they want either modal, or non-modal, and have complete control over their dialog logic.The current implementation looks like this:
The idea here is that Prism will no longer provide any built-in dialogs like Notification or Confirmation. Mainly because the Prism implementations are UGLY and will never match the styling of your beautiful WPF application. So, it's important that you are able to register your own dialogs.
Create Your Dialog View
Your dialog view is a simple UserControl that can be designed anyway you please. The only requirement it has a ViewModel that implements
IDialogAware
set as it's DataContext. Preferrably, it will utilize theViewModelLocator
Create Your Dialog ViewModel
Next you need a ViewModel that implements IDialogAware which is defined as follows
There is currently a
DialogViewModelBase
class that implements this for you to make it easier to create your dialog VMs.In your VM, you place any new properties and methods that you need in order for your dialog to function. The important thing is when you want to close the dialog, just call
RaiseCloseDialog
and provide yourDialogResult
.Register the Dialog
To register a dialog, you must have a View (UserControl) and a corresponding ViewModel (which must implement
IDialogAware
). In theRegisterTypes
method, simply register your dialog like you would any other service by using theIContainterRegistery.RegisterDialog
method.Using the Dialog Service
To use the dialog service you simply ask for the service in your VM ctor.
Then call either
Show
orShowDialog
providing the name of the dialog, any parameters your dialogs requires, and then handle the result via a call backSimplify your Application Dialog APIs
The intent of the dialog API is not to try and guess exactly what type of parameters your need for all of your dialogs, but rather to just create and show the dialogs. To simplify common dialogs in your application the guidance will be to create an extension methods to simplify your applications dialogs.
For example:
Then to call your Notifications use the new and improved API that you created specifically for your app.
Register a Custom Dialog Window
It's very common to be using a third-party control vendor such as Infragistics. In these cases, you may want to replace the standard WPF Window control that hosts the dialogs with a custom Window class such as the Infragistics XamRibbonWindow control.
In this case, just create your custom Window, and implement the
IDialogWindow
interface:Then register your dialog window with the
IContainerRegistry
.To clarify, this is to replace the PopupWindowAction. I want to remove that mess completely from Prism