1

Im looking for a way to disable a tab within a TabbedPage, here my example of two tabs

<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns=".."
             xmlns:x=".."
             x:Class="App.Views.Pages_Tabbed"
            x:Name="myTabs"
            xmlns:page="clr-App.Views">

    <TabbedPage.Children>
        <page:MemberShip x:Name="firstPage" ></page:MemberShip>
        <page:Consent x:Name="secondPage"></page:Consent>
        <page:Question x:Name="thirdPage"> </page:Question >
    </TabbedPage.Children>

</TabbedPage> ```
I tried to set the Page to IsEnabled = false  or IsVisible= false but not working .. it hide only content.  
Also i followed https://stackoverflow.com/questions/54657758/how-to-set-the-currentpage-property-of-a-tabbedpage-in-the-oncurrentpagechanged but it crash the app cuz of the infinite loop. 
DevQc
  • 113
  • 8
  • Does this answer your question? [Xamarin Forms Disable swipe between pages in TabbedPage](https://stackoverflow.com/questions/45820704/xamarin-forms-disable-swipe-between-pages-in-tabbedpage) – ToolmakerSteve Dec 01 '21 at 18:16

1 Answers1

1

The official does not seem to provide a way to directly disable the tab.

You can also hide the tab temporarily when you don't want the user to click on it. Let the user load it when he can click.

Here is the background code:

public partial class TabbedPage1 : TabbedPage
{
    public static TabbedPage theTabbedPage {get; set;}
    public TabbedPage1()
    {
        InitializeComponent();
        theTabbedPage = this;
        theTabbedPage.Children.RemoveAt(1);//Hide the second tab
    }
}

When the user can click, use abbedPage1.theTabbedPage.Children.Insert(1,new Page2() {Title="page2"}); to add the tab.

Hope this method can help you too.

Wen xu Li
  • 1,698
  • 1
  • 4
  • 7
  • thanks for this solution , but the problem , when i send command ( GoToNextPage .. i cant call ( abbedPage1.theTabbedPage.Children.Insert(1,new Page2() {Title="page2"});) – DevQc Dec 02 '21 at 17:56
  • The first parameter of the .Insert(); method is the index of the array. You need to know the current number of elements in the array. The number of pages is increased by one each time you add a page. The number of deleted pages is reduced by one. – Wen xu Li Dec 03 '21 at 00:54