Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access a specific Shell FlyoutItem from another page in Xamarin Forms

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?

like image 800
fnllc Avatar asked Nov 29 '25 18:11

fnllc


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();
 
like image 144
ColeX - MSFT Avatar answered Dec 02 '25 20:12

ColeX - MSFT



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!