如何在xamarin表单中单击后退按钮时在选项卡页面之间导航
答案 0 :(得分:0)
试试这个你需要覆盖OnBackButtonPressed事件并保持堆栈
通常,通过单击选项卡本身来完成选项卡页面中的导航。
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();
}