Pressing buttons multiple times loads multiple pag

2019-02-16 00:50发布

I want to solve the problem, when I push the button several times - offers many of the same pages. I found here such code.

var stack = Navigation.NavigationStack;
if (stack[stack.Count - 1].GetType() != typeof(DetailsPage))
await Navigation.PushAsync (new DetailsPage ());

Navigation.NavigationStack - works fine. Navigation.ModalStack - doesnt work. But I cant get Name.

Please help me with this solution.

1条回答
太酷不给撩
2楼-- · 2019-02-16 01:48

there are various threads on this common issue, I can see on the forums that you already commented on it, there are also NavigationExtensions class:

public static class NavigationExtensions
{
    public static async Task PushModalAsyncSingle(this INavigation nav, Page page, bool animated = false)
    {
        if (App.Navigation.ModalStack.Count == 0 || 
            App.Navigation.ModalStack.Last().GetType() != page.GetType())
        {
            await nav.PushModalAsync(page, animated);
        }
    }

    public static async Task PushAsyncSingle(this INavigation nav, Page page, bool animated = false)
    {
        if (App.Navigation.NavigationStack.Count == 0 ||
            App.Navigation.NavigationStack.Last().GetType() != page.GetType())
        {
            await nav.PushAsync(page, animated);
        }
    }
}

Here is the discussion: https://forums.xamarin.com/discussion/29787/double-tapping-in-xamarin-forms-on-android

查看更多
登录 后发表回答