1

在我的 AppShell.xaml.cs 页面中,我可以轻松访问 Shell 的 FlyoutItems:

accountFlyoutItem.IsEnabled = false;
accountFlyoutItem.IsVisible = false;

但是,您如何从另一个页面访问这些?我发现的唯一方法是尝试遍历“Shell.Current.FlyoutItems”。有没有我想念的更简单的方法?

4

1 回答 1

1

Shell.Current.CurrentItem用于获取当前选定的弹出窗口。

如果我们想FlyoutItem在你在xaml()中命名后访问特定的<FlyoutItem x:Name="a">,我们可以通过以下两种方式获取

  • 在构造函数中创建一个全局公共变量AppShell并赋值。
 public ShellItem AItem;

        public AppShell()
        {
            InitializeComponent();
            RegisterRoutes();
            BindingContext = this;

            AItem = a;
        }

//In another page

var item = (Shell.Current as AppShell).AItem;
  • 创建一个返回项目的方法,这样我们就不需要创建公共变量了。
   public ShellItem GetA()
        {
            return a;
        }
//In another page

var item = (Shell.Current as AppShell).GetA();
 
于 2021-04-03T03:22:39.450 回答