Страница с вкладками OnBackButtonПрессованная в формах Xamarin - PullRequest
0 голосов
/ 01 июня 2018

Как перемещаться между страницами с вкладками при нажатии кнопки «Назад» в формах xamarin

1 Ответ

0 голосов
/ 01 июня 2018

Попробуйте это, вам нужно переопределить событие 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();
}
...