Search code examples
xamarin.formsnavigation-drawermaster-detailreloaddata

OnApearing() method is not firing second time in Mater details page of xamarin forms


I'm using a custom master details page. On that page, I implemented the onAppearing() method. It's firing the first time (When I run the program.Master detail page is the root page of my app) only. When I clicked the hamburger icon to open the Navigation drawer, that OnAppearing() is not firing.

MasterDetailsPage CS Code:

public partial class MainMasterDetailPage : MasterDetailPage
    {
        public MainMasterDetailPage()
        {
            InitializeComponent();
            
            NavigationPage.SetHasBackButton(this, false);
            NavigationPage.SetHasNavigationBar(this, false);
           
            ListOfSettings.IsVisible = false;

            this.IsPresented = false;

            Detail = new NavigationPage(new DashboardTabbedPage());

        }
        protected override async void OnAppearing()
        {
            base.OnAppearing();
            ListOfSettings.IsVisible = false;
        }
}

enter image description here enter image description here


Solution

  • I used IsPresentedChanged property. Please check the below code.

    public MainMasterDetailPage()
            {
                InitializeComponent();
    
                NavigationPage.SetHasBackButton(this, false);
                NavigationPage.SetHasNavigationBar(this, false);
                ListOfSettings.IsVisible = false;
                this.IsPresented = false;
                Detail = new NavigationPage(new DashboardTabbedPage());
    
                this.IsPresentedChanged += hideSettingMenu;
    
            }
            public void hideSettingMenu(object sender, EventArgs args)
            {
                ListOfSettings.IsVisible = false;
            }