本文介绍了多次按下按钮会加载多个页面(Android)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我几次按下按钮时,我想解决该问题-提供许多相同的页面.我在这里找到了这样的代码.
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
-正常工作.Navigation.ModalStack
-无法获取名称.
Navigation.NavigationStack
- works fine.Navigation.ModalStack
- doesnt work. But I can
t get Name.
推荐答案
在这个常见问题上有各种各样的话题,我可以在论坛上看到您已经对此发表过评论的话题,还有NavigationExtensions
类:
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);
}
}
}
这里是讨论: https://forums.xamarin.com/discussion /29787/double-tapping-in-xamarin-forms-on-android
这篇关于多次按下按钮会加载多个页面(Android)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!