Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

Using PopAsync to pop two or more pages at once?

$
0
0

I have created a Forms Shared Project solution and have multiple pages that go Page1 to Page2 to Page3 to Page4. From Page4 I want to pop out to Page1 or Page2 on the click of a button. But anything I have tried to PopAsync multiple times at once has failed (either an exception is thrown or it just doesn't pop more than one page).

My code in Page4 looks like this (Pages 1, 2, and 3 are on the page stack):

public class Page4 : ContentPage
    {
        public Page4 ()
        {
            var button = new Button () { Text = "Pop Two Pages" };
            button.Clicked += async delegate {
                await Navigation.PopAsync ();
                await Navigation.PopAsync ();
            };
            Content = button;
        }
    }

The above code throws InvalidOperationException:

System.InvalidOperationException: Operation is not valid due to the current state of the object
at System.Collections.Generic.Stack`1[Xamarin.Forms.Page].Pop () [0x0000b] in /Developer/MonoTouch/Source/mono/mcs/class/System/System.Collections.Generic/Stack.cs:120
at Xamarin.Forms.NavigationProxy.OnPopAsync () [0x00000] in :0
at Xamarin.Forms.NavigationProxy.PopAsync () [0x00000] in :0
at NavigationTest.Page4+c__async0.MoveNext () [0x0007b] in /Users/devinrose/Dropbox/KetraProject/MobileExperiments/NavigationTest/NavigationTest/Page4.cs:15

My guess is that the second PopAsync is not valid because it has already popped this page off the stack. Using a single PopToRootAsync doesn't work due to a known Xamarin bug on iOS. Any ideas?


Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>