ShowDialog with Callback or ShowDialogAsync? #3282
-
Now that the dialogservice is available for .NET MAUI in v9 I've noticed there is a remark on the .ShowDialog method saying "This is for backwards compatibility. Use DialogCallback instead." I am migrating from Xaamarin Forms where I was using the The question is, should I migrate to use the ShowDialogAsync method and just return the IDialogResult and deal with it without a callback? Or, should I migrate to the "new?" DialogCallback for which I can't seem to find any examples or doccumentation about? For completeness I am using an extension class and most of the dialogs are confirmation or Alert Dialogs (Yers\No, Alert Message, Enter Value etc) that need to be modal\blocking. I feel like ShowDialogAsync is nicer but wanted to ask if thats the best case moving forward? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
So the answer is really it depends on your needs. It sounds like you want: var result = await dialogs.ShowDialogAsync("foo");
if (result.Parameters.GetValue<bool>("bar"))
{
// do something
} If that's what you need then that's probably the best API to use. But on the other hand you could potentially do this too... it really all depends on your needs. private void OnSomeCommandExecuted()
{
dialogs.ShowDialog("foo", DialogCallback.OnCloseAsync(async result => {
if (result.Parameters.GetValue<bool>("bar"))
await DoSomething();
});
} |
Beta Was this translation helpful? Give feedback.
-
Thanks Dan for the clarifications. Considering I was coming from the "make it async using the TaskCompletionSource" approach, the Async method makes more sense for my use case. Kind of feel a bit funny looking at it now. 😄 (The Tuple also really sets it off!)
I do like the DialogCallback approach as well. I must've been having a moment becasue I couldn't figure out how to use that in an Extension method from he docs but your second code block made it all make sense. Cheers again. |
Beta Was this translation helpful? Give feedback.
btw the samples are in the docs:
https://docs.prismlibrary.com/docs/dialogs/index.html#on-close