【问题标题】:How to disable Tab on TabbedPage xamarin forms?如何禁用 TabbedPage xamarin 表单上的选项卡?
【发布时间】:2022-01-08 06:26:27
【问题描述】:

我正在寻找一种方法来禁用 TabbedPage 中的选项卡, 这是我的两个选项卡的示例

<?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. 

【问题讨论】:

标签: xamarin.forms tabs


【解决方案1】:

官方好像没有提供直接禁用tab的方法。

当您不希望用户点击它时,您也可以暂时隐藏它。让用户在可以点击时加载它。

这是后台代码:

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

当用户可以点击时,使用abbedPage1.theTabbedPage.Children.Insert(1,new Page2() {Title="page2"});添加标签。

希望这个方法也能帮到你。

【讨论】:

  • 感谢这个解决方案,但问题是,当我发送命令时(GoToNextPage ..我无法调用(abbedPage1.theTabbedPage.Children.Insert(1,new Page2() {Title="page2"} );)
  • .Insert()的第一个参数;方法是数组的索引。您需要知道数组中当前元素的数量。每添加一页,页数就会增加一。被删除的页面数减一。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-05-21
  • 2020-12-14
  • 1970-01-01
  • 2019-03-20
  • 2019-05-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多