本文介绍了多次按下按钮加载多个页面(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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!