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

Repeated PushAsync/PopAsync issues

$
0
0

Hi Guys,

I was wondering if anyone could help me identify what is wrong with this bit of sample code. Basically I'm trying to push a new instance of the same page if a user hits the back button. This works once, but fails the second time the back button is pressed.

(NB: this is obviously simplified down terribly compared to the proper version, but the example highlights the issue)

All the best,

Paul.

ps - not sure why the code markdown tag isn't working properly??


public class App
{
public static Page GetMainPage()
{
return new NavigationPage(new TopPage());
}
}

public class TopPage : ContentPage
{
    public TopPage()
    {
        var button = new Button { Text = "PushPage" };
        button.Clicked += async (sender, args) => { await Navigation.PushAsync(new PushPage()); };
        Content = new StackLayout
        {
            Children =
            {
                new Label() {Text = "TopPage"},
                button,
            }
        };
    }
}

public class PushPage : ContentPage
{
    public PushPage()
    {
        Content = new Label() { Text = "PushPage, Time: " + DateTime.Now.ToLongTimeString() };
    }

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

        await Navigation.PushAsync(new PushPage());
    }
}


Viewing all articles
Browse latest Browse all 58056

Trending Articles



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