Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do you close a view from another view in .net maui?

I am trying to implement a loading/is busy logic in my app. When the item is selected from a collection view it shows a popup of a activity indicator which works fine. But, I am unable to close the popup once the other view loads. I have tried calling Close() but that doesnt do anything. So pretty much just trying to figure out the best way to show a activity indicator then close it once the process is done.

async void ItemSelected(object sender, SelectionChangedEventArgs e)
    {
        var popup = new LoadingPopup();
        this.ShowPopup(popup);
        var item = e.CurrentSelection.FirstOrDefault();
        if (item != null)
        {
            await Navigation.PushAsync(new YearPage(item) {BindingContext = item });
            
            //await Application.Current.MainPage.Navigation.PushAsync(new YearPage
            //{
            //    BindingContext = item
            //});
        }
    }

Calling close on the popup from a different view page(as the method doing the work is on a different page and I want to close the popup once it is done) doesnt work.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

you need to pass a reference to the popup to the 2nd page

var popup = new LoadingPopup();
this.ShowPopup(popup);
var item = e.CurrentSelection.FirstOrDefault();
if (item != null)
{
  await Navigation.PushAsync(new YearPage(item, popup) {BindingContext = item });
   

then you would have to modify the YearPage constructor to accept that 2nd parameter

then you would have a public method on LoadingPopup to dismiss via the Close() method

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading