首页 > 解决方案 > 使用条件时如何从 TabbedPage 隐藏选项卡(xamarin 表单)

问题描述

我有以下问题,我有一个系统,当输入时有一个带有 TabbedPage 的 xaml 使用不同的内容页面(例如选项卡),但是当满足某个条件时,我需要其中一个为用户隐藏。

我怎样才能做到这一点?

干杯

标签: c#visual-studioxamarinxamarin.formsxamarin-studio

解决方案


在页面的构造函数中,只需在添加子页面时检查。我不知道是否有一种简单的方法可以在 XAML 中做同样的事情

public class MyPage : TabbedPage
{
  public MyPage() 
  {

    this.Children.Add(new Page1());
    this.Children.Add(new Page2());

    if (some conditional check based on user) 
    {
      this.Children.Add(new Page3());
    }

  }
}

推荐阅读