Is it possible to hide a specific FlyoutItem when using Xamarin Forms Shell?

Viewed 3565

I am using Xamarin Forms Shell and I want to be able to hide some items of my Flyout depending on some parameters (the current page for instance) but I can't find any method or property to change the visibility of a FlyoutItem.

Is it possible to programmaticaly hide some FlyoutItem (not the complete Flyout just some items) ?

5 Answers

As of this moment it is not possible, there is a current Issue regarding this.

However, I managed to find another thread, where there might be a solution with dynamic creating flyout items. You can check it here.

Had the same issue, here is my solution. I created a style, and set that to hidden. Then I update my MenuItem in the backend, depending what is needed.

Style

<Style
            ApplyToDerivedTypes="True"
            Class="MenuItemLayoutStyleHidden"
            TargetType="Layout">
            <Setter Property="IsVisible" Value="False" />
        </Style>

Menu Item

<MenuItem
    x:Name="btnLogout"
    Clicked="btnLogoutClick"
    IconImageSource="icon_about.png"
    StyleClass="MenuItemLayoutStyle"
    Text="Logout" />

Backend Code

if (user.isLoggedIn)
        {
            btnLogout.@class.Clear();
            btnLogout.@class.Add("MenuItemLayoutStyle");
        }
        else
        {
            btnLogout.@class.Clear();
            btnLogout.@class.Add("MenuItemLayoutStyleHidden");
        }

I was searching how i can hide a MenuItem in Shell Flyout because i didn't want to use FlyoutItem. I needed the Clicked event. I managed to hide a MenuItem with:

<MenuItem Text="Arrivals" x:Name="Arrivals" Clicked="MenuItem_Clicked" Shell.FlyoutItemIsVisible="False"/>
Related