[英]Tabbed Page OnBackButtonPressed in Xamarin Forms
在Xamarin表单中单击后退按钮时如何在选项卡式页面之间导航
Try this you need to override OnBackButtonPressed event and also maintain a stack 尝试此操作,您需要覆盖OnBackButtonPressed事件并维护一个堆栈
Generally navigation in Tabbed pages are done by clicking on Tabs itself. 通常,在选项卡式页面中导航是通过单击选项卡本身来完成的。
protected Stack<Page> TabStack { get; private set; } = new Stack<Page>();
protected override void OnCurrentPageChanged()
{
// current page
var page = CurrentPage;
if (page != null)
{
// Push the page onto the stack
TabStack.Push(page);
}
base.OnCurrentPageChanged();
}
protected override bool OnBackButtonPressed()
{
// Go to previous page in the stack. First,
//pop off the top page since this represents the
// current page we are on.
if (TabStack.Any())
{
TabStack.Pop();
}
// Check if we have any pages left
if (TabStack.Any())
{
// Pop off the next page and Launch it
CurrentPage = TabStack.Pop();
// Return true to indicate we handled this scenario
return true;
}
// We don't have any more pages in the stack so do the default
//funcationlity
return base.OnBackButtonPressed();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.