Home > Back-end >  Xamarin: Modal from not popping
Xamarin: Modal from not popping

Time:02-02

since a couple of weeks I have the problem that a modal form which provides a spinner and a label is not popping anymore. It was running in older versions but not with all NuGet Packages updated. Any idea what this can be? Funnywise it is working on some forms and not on others.

protected async override void OnAppearing()
    {
       
        try
        {
            await Navigation.PushModalAsync(new BusyPopUpPage("loading products"));
            
            //ActivityTracker.StartSpinner(true);
            base.OnAppearing();
            IsFiltered = false;
            LblAttributesVisible = false;
            AllProducts = await App.AllProductsController.GetAllProducts();

            grouped = new ObservableCollection<AssortmentGroups>();

            GroupProducts();
            AllProductsListView.IsGroupingEnabled = true;
            AllProductsListView.ItemsSource = grouped;
            await Navigation.PopModalAsync();
        }
        catch (Exception ex)
        {
            await CreateNewBug.CreateANewBug(ex.Message,"Error in Module "   ex.Source,"\nMessage---\n{ 0}"   ex.Message   "\nInnerException---\n{ 0}"   ex.InnerException   "\nStackTrace---\n{ 0}"   ex.StackTrace   "\nTargetSite---\n{ 0}"   ex.TargetSite);
            ToastOptions toastOptions = Message.ShowMessage("An error was raised and a new bug created in our system.", "error");
            await this.DisplayToastAsync(toastOptions);
        }
        
    }

CodePudding user response:

I recommend another solution for your loading page. Instead of pushing and popModel create overlapping pages. Then show and hide them whenever you want. example:

 <Grid>
            
            <!--here you can add what u want to display on your page-->
            
            
        <Grid x:Name="LoadingGrid" BackgroundColor="White" IsVisible="false" >
            <StackLayout VerticalOptions="Center" HorizontalOptions="Center">
               
                <ActivityIndicator HeightRequest="50"  Color="#2196F3" IsRunning="True" />
               
            </StackLayout>
        </Grid>
  </Grid>

in you code behind

protected async override void OnAppearing()
    {
       
        try
        {
           this.LoadingGrid.IsVisible = true;
            
            //ActivityTracker.StartSpinner(true);
            base.OnAppearing();
            IsFiltered = false;
            LblAttributesVisible = false;
            AllProducts = await App.AllProductsController.GetAllProducts();

            grouped = new ObservableCollection<AssortmentGroups>();

            GroupProducts();
            AllProductsListView.IsGroupingEnabled = true;
            AllProductsListView.ItemsSource = grouped;
            
            this.LoadingGrid.IsVisible = false;
        }
        catch (Exception ex)
        {
            await CreateNewBug.CreateANewBug(ex.Message,"Error in Module "   ex.Source,"\nMessage---\n{ 0}"   ex.Message   "\nInnerException---\n{ 0}"   ex.InnerException   "\nStackTrace---\n{ 0}"   ex.StackTrace   "\nTargetSite---\n{ 0}"   ex.TargetSite);
            ToastOptions toastOptions = Message.ShowMessage("An error was raised and a new bug created in our system.", "error");
            await this.DisplayToastAsync(toastOptions);
        }
        
    }

CodePudding user response:

It is very strange. I reduce my code to the following:

 await Navigation.PushModalAsync(new BusyPopUpPage("loading products"));
            LoopCounter  ;
            //base.OnAppearing();
            //IsFiltered = false;
            //LblAttributesVisible = false;
            //AllProducts = await App.AllProductsController.GetAllProducts();

            //grouped = new ObservableCollection<AssortmentGroups>();

            //GroupProducts();
            //AllProductsListView.IsGroupingEnabled = true;
            //AllProductsListView.ItemsSource = grouped;
            await Navigation.PopModalAsync();
            await DisplayAlert("Info", "LoopCounter="   LoopCounter, "OK");

So, we just have the PushModalAsync and the PopModalAsync. All other code not running currently. I added a loop-counter because I see that the code is running 2 times. If I run the code with the PopModalAsync it runs 2 times through the whole code. If I remove the PopModalAsync it only runs 1 time through the code. Maybe this is the problem. I will also continue testing

  •  Tags:  
  • Related