How to Use Navigation Push ASync in Master Detail Page Menu

TheodorusGumilangTheodorusGumilang USMember ✭✭
edited November 10 in Xamarin.Forms

I want to make my xamarin forms app when the menu item is clicked instead change the master detail page it go to another page and shows navigation bar with back button in the top. but i got confused in how to change the on menu item selected, here is my onmenuitemSelected

private void OnMenuItemSelected(object sender, SelectedItemChangedEventArgs e)
{

        var item = (DrawerItem)e.SelectedItem;
        Type page = item.TargetType;

        //Navigation.PushAsync((Page)Activator.CreateInstance(page));
        //new NavigationPage((Page)Activator.CreateInstance(page));

        Detail = new NavigationPage((Page)Activator.CreateInstance(page));
       IsPresented = false;
    }

As you can see in the comment tag i already try to do Navigation.Push async and tried New NavigationPage only without Detail but when im click the menu item its do nothing, so what code should i write to do that.

Tagged:

Best Answer

  • ElzuElzu INMember ✭✭
    Accepted Answer

    Try this code
    Detail = new NavigationPage((Page)Activator.CreateInstance(typeof(DriverHomePage)));
    here 'DriverHomePage' is my detail page..then

    private void OnMenuItemSelected(object sender, SelectedItemChangedEventArgs e)
    {
    var item = (MasterPageItem)e.SelectedItem;
    Type page = item.TargetType;
    // Detail = new NavigationPage((Page)Activator.CreateInstance(page));
    Detail.Navigation.PushAsync((Page)Activator.CreateInstance(page));
    IsPresented = false;
    }

Answers

  • TheodorusGumilangTheodorusGumilang USMember ✭✭

    ok let me clear my question maybe everyone dont understand my question is. So what i want is like create navigation page stack, instead changing the Detail page. as you can see my code is "Detail = new NavigationPage((Page)Activator.CreateInstance(page));" and its change the Detail page what i want is create new navigation page so when i press the back button its go back to Detail page

  • ElzuElzu INMember ✭✭
    Accepted Answer

    Try this code
    Detail = new NavigationPage((Page)Activator.CreateInstance(typeof(DriverHomePage)));
    here 'DriverHomePage' is my detail page..then

    private void OnMenuItemSelected(object sender, SelectedItemChangedEventArgs e)
    {
    var item = (MasterPageItem)e.SelectedItem;
    Type page = item.TargetType;
    // Detail = new NavigationPage((Page)Activator.CreateInstance(page));
    Detail.Navigation.PushAsync((Page)Activator.CreateInstance(page));
    IsPresented = false;
    }

  • TheodorusGumilangTheodorusGumilang USMember ✭✭

    @Elzu thanks bro its work, this is the answer i'm looking for

Sign In or Register to comment.