Xamarin.Forms/FreshMVVM - Yes/no style popup

103 Views Asked by At

This is probably a quite silly question, but it nonetheless needs an answer: I have created a small, custom MessageBox for my Xamarin.Forms project using Rg.Plugins.Popup - however, when trying to extend it to include a confirmation modal, I cannot find a way to detect whether the user has confirmed or cancelled the action from the popup.

Here's the code to open the popup

Message msgBox = new Message(); /*new instance of my Message wrapper class*/
msgBox.State = "msg_info";
msgBox.MessageTitle = "My_Message_Title";
msgBox.MessageText = "My_Message_Caption";

await CoreMethods.PushPopupPageModel<MessageBoxPageModel>(msgBox); /*using the FreshMVVM.Popup extension to navigate to the popup*/

/*need to check for confirmation here and delete the line or do nothing*/

So what I'm looking for, in short, is the appropriate way to detect whether the user has tapped the "Yes" or "No" button on the popup so I can, for example, delete a row from my database or not.

I looked into MessagingCenter but that seems to work from ViewModel to View, not ViewModel to ViewModel - Rg.Plugins.Popup suggest using a CallbackEvent, but CallbackEvents are, or so I've understood, not compatible with FreshMVVM/the MVVM pattern.

1

There are 1 best solutions below

0
On

Just so this isn't kept open:

I ended up using a DevExpress Popup control as a Yes/No dialog - slightly less customization, but much more straightforward to use since I already had the DevExpress controls loaded.

Detail link for the DevExpress Popup control for those interested https://docs.devexpress.com/MobileControls/DevExpress.XamarinForms.Popup.DXPopup