Access a specific Shell FlyoutItem from another page in Xamarin Forms

Viewed 662

In my AppShell.xaml.cs page I can easily access the FlyoutItems of the Shell:

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

However, how do you access these from another page? The only way I found was to try to iterate through the "Shell.Current.FlyoutItems". Is there a simpler way I'm missing?

1 Answers

Shell.Current.CurrentItem is used to get the current selected flyout .

If we want to access specific FlyoutItem after you named it in xaml (<FlyoutItem x:Name="a">) , we can get it from the following two ways

  • Create a global public variable in AppShell and assign the value in constructor.
 public ShellItem AItem;

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

            AItem = a;
        }

//In another page

var item = (Shell.Current as AppShell).AItem;
  • Create a method to return the item , in this way we don't need to create the public variable .
   public ShellItem GetA()
        {
            return a;
        }
//In another page

var item = (Shell.Current as AppShell).GetA();
 
Related