Nyanko
Nyanko

Reputation: 97

Xamarin.Forms - How to disable Tab on TabbedPage?

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. :)

Upvotes: 7

Views: 5994

Answers (2)

JHo
JHo

Reputation: 466

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;
    }

Upvotes: 2

der_michael
der_michael

Reputation: 3352

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.

Upvotes: 4

Related Questions