Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin.Forms - How to disable Tab on TabbedPage?

Tags:

xamarin

I'm looking for a way to disable a tab within a TabbedPage. The tab should be still showing up in the TabbedPage header but simply be disabled.

I tried to set the Page to IsEnabled = false but apparently this is not how you do it or I did it wrong. :)

like image 960
Nyanko Avatar asked Jun 28 '14 00:06

Nyanko


2 Answers

You can create a custom renderer for a tabbed page control and disable user interaction in your platform specific implementation of the renderer.

For example your renderer for iOS would use the UITabBarControllerDelegate Protocol to override

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController

and return NO for the tab that should not be selectable. The solution for Android or Windows Phone would work similar.

like image 197
der_michael Avatar answered Sep 27 '22 20:09

der_michael


Here is my self-contained take on @joeriks method, which is a nice quick/simple solution. Annoying that the event args are just EventArgs.

Just add this to your TabbedPage .cs file somewhere.

    Page _lastKnownPage;
    protected override void OnCurrentPageChanged()
    {
        base.OnCurrentPageChanged();
        if (CurrentPage.IsEnabled)
            _lastKnownPage = CurrentPage;
        else
            CurrentPage = _lastKnownPage;
    }
like image 28
JHo Avatar answered Sep 27 '22 22:09

JHo