Search code examples
xamarin.formstabbedpage

xamarin forms: How can I close the tabbedpage and show the previous page when click a tab?


I have a tabbed page in my xamarin forms project having 4 tabs. I am opening the tabbed page from the home page(normal content page) and initially showing 2nd tab.

When I click the first tab I need to exit from the tabbed page and show the homepage (previous page) in UI.

How can I do this? Is there any tabbed page events are available?


Solution

  • Yes, you can used the CurrentPageChanged event on TabbedPage. If you are in a navigation page, you can subscribe and navigate back, but if you just want to replace the top-level page, you can do this:

            CurrentPageChanged += (sender, e) =>
            {
                if (CurrentPage == Children.First())
                {
                    Application.Current.MainPage = {your home page instance};
                }
            };