0

I have an app with two pages. One of them is the MainPage, which is opened first when the app is opened. The second page is there to update values (user input), sent them to a server and returning to the MainPage (all in one click under one button). For loading the new values on the MainPage, I'm using an ACR UserDialog and here comes the problem.

The ACR UserDialog must be created at two location:

  • One in the OnAppearing of the MainPage, so that when the app is opened a nice dialog is shown while loading the data.
  • One in the second page because of the values being sent to the server.

Both work, but when I press the button to upload the values to the server, the first dialog pops up loading and then the app returns to the MainPage while quickly switching from the first dialog to the second dialog from the OnAppearing. I would like this transition to be smooth: both texts are different and I want to keep the loading going while only updating the text (so that the loading dialog does not switch quickly).

Is this possible?

EDIT: code snippits I have created a demo, but I cannot send files here.

MainPage:

protected async override void OnAppearing()
        {
            base.OnAppearing();

            UserDialogs.Instance.ShowLoading("Getting Information");
            await Task.Delay(2000);

            // Do stuff

            UserDialogs.Instance.HideLoading();
        }

SecondPage:

private async void Button_Clicked(object sender, EventArgs e)
        {
            UserDialogs.Instance.ShowLoading("Saving Information");
            await Task.Delay(2000);

            // Do stuff

            await Navigation.PopAsync();
        }

GIF of the situation: enter image description here

Ganesh Gebhard
  • 453
  • 1
  • 7
  • 20
  • Do you want to make the slow transition between the two dialogs? I recommend you can set a delay between the two dialogs. In addition, you can try to make the method async. – Guangyu Bai - MSFT Feb 09 '23 at 02:56
  • No instant. So when the first dialog goes to the second dialog, the dialog should stay spinning (without disappearing) and the text should be updated. – Ganesh Gebhard Feb 09 '23 at 03:05
  • Can you provide some code snippet? – Guangyu Bai - MSFT Feb 09 '23 at 05:09
  • Take a look at the edit I made: the code snippits of the two pages and a GIF showing the result. You can see that the dialog closes and a new one opens. I want this to be one dialog with only text updates. – Ganesh Gebhard Feb 09 '23 at 15:20
  • that's simply because when you return to your MainPage the `OnAppearing` method executes again, as always you enter a page `OnAppearing` will be invoked. Maybe you can use [MessagingCenter](https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/messaging-center) to prevent the dialog executes on return. – FabriBertani Feb 10 '23 at 01:29
  • I read the code you provided and I found that you use `UserDialogs.Instance.ShowLoading("Getting Information");` in the `OnAppearing() `method that is the reason why there shows two dialogs. The code in OnAppearing method will run before you enter the mainpage. – Guangyu Bai - MSFT Feb 10 '23 at 02:25
  • Yes I know why it happens, the problem is that I don't know how to make sure it doesn't happen. Is there a piece of code that prevents it? Or an option in ACR UserDialogs that I'm missing? – Ganesh Gebhard Feb 10 '23 at 02:28
  • ACR UserDialogs do not have the option to prevent the dialog showing in the mainpage. First solution, You can remove the UserDialogs in the OnAppearing method. Second, you can set a judgment statement before the ACR UserDialogs in the OnAppearing method, so when you back to the mainpage you can make the dialog not to work. – Guangyu Bai - MSFT Feb 10 '23 at 05:15

0 Answers0