Hide Tab From Tabbed Page XAML

Anonymous
2021-02-24T09:47:15.937+00:00

Hi Guys,

I have a Xamarin.Forms Project With a Navigation page witch contains a TabbedPage with 3 ContentPages Inside Descibed in a XAML File.

But depending on a bool I have to hide or not a tab of the tabbedPage.
I used the IsVIsible property with a bindable variable But it just hides the content of the page from me but does not remove the tab from the page tabbed from me, have a solution to remove the tab from user view.

<ContentPage Title="{x:Static res:UI.SettingTabPreferenceLabelKey}" IsVisible="{Binding IsFromLoginWithoutConnexion}">  

71448-image.png

Thank you for your answers
Max. B

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,310 questions
XAML
XAML
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
775 questions
0 comments No comments
{count} votes

Accepted answer
  1. JarvanZhang 23,951 Reputation points
    2021-02-24T12:04:13.66+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    1.The TabbedPage class doesn't provide a property or method to hide the tab. For this function, try to define the tabbedPage's children using the Remove and Insert method.

       TabbedPage theTabbedPage = App.Current.MainPage as TabbedPage;  
       public void HideTab(int index)  
       {  
           if (index < theTabbedPage.Children.Count)  
           {  
               theTabbedPage.Children.RemoveAt(index);  
           }  
       }  
       public void AddTab(int index)  
       {  
           // Adjust this page as you want  
           if (!theTabbedPage.Children.Contains(thePage))  
           {  
               theTabbedPage.Children.Insert(index, thePage);  
           }  
       }  
    

    2.If you want to change the template of the application, you could create two tabbedPages to display the different status. Change the App.Current.MainPage when the bool property is changed.

       public partial class App : Application  
       {  
           public App()  
           {  
               InitializeComponent();  
    
               if (_value)  
               {  
                   MainPage = new TabbedPage1();  
               }  
               else  
               {  
                   MainPage = new TabbedPage2();  
               }  
           }  
           ...  
       }  
    

    Best Regards,

    Jarvan Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2021-02-24T13:24:17.283+00:00

    Hi,

    Thank's for your answer.
    It will help.
    I'll try this solution soon :)
    Thanks again

    Max B

    0 comments No comments