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. :)
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.
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With