Search code examples
c#xamarinxamarin.formsxamarin.forms.shell

event when the left menu is opened in xamarin forms shell


I am working with xamarin forms shell. I have 1 image and 1 label to assign the name and profile picture of the user. I want every time the menu opens (press the button or drag to the right) to update that value again, but I can't find any events related to it. Someone please help me badly


Solution

  • Since there is no and won't be events such OnFlyoutOpened OnFlyoutClosed, you can listen to your Shell PropertyChanged event, if the property is FlyoutIsPresented then execute your code:

    public AppShell()
    {
        InitializeComponent();
        PropertyChanged += Shell_PropertyChanged;
    }
    
    private void Shell_PropertyChanged(object sender, PropertyChangedEventArgs e)
    {
        if (e.PropertyName.Equals("FlyoutIsPresented"))
            if (FlyoutIsPresented)
                OnFlyoutOpened();      //you will execute your code here
            else
                OnFlyoutClosed();
    }
    

    Depending on your requirement you will define OnFlyoutOpened() and OnFlyoutClosed() methods.

    Thanks to @PureWeen guidance in discussion.