doxsi
doxsi

Reputation: 1024

Xamarin Forms: Open menu by custom button in MasterDetail based project

In my MasterDetail based project, I need a custom appearence for the navigation part for a specific detail page. To avoid rendering a custom Navigation, I set

    NavigationPage.SetHasNavigationBar(this, false);

so navigation disappear an then I create by grid a background and a button like:

<Grid>
   <Image Source="BackgroundImage.png"/> <!-- This should fill the grid -->
   <Image Source="back_button" HorizontalOptions="StartAndExpand" Aspect="AspectFit" >
      <Image.GestureRecognizers>
        <TapGestureRecognizer Tapped="Handle_Tapped"/>
      </Image.GestureRecognizers>
    </Image>
</Grid>

Handle_Tapped should be manage the open/hide menu of master detail. I think i need to manage the IsPresented properties like

    MasterDetailPage nav = new MasterDetailPage();
    nav.IsPresented = true;

but that do nothing. Any help?

Upvotes: 0

Views: 1246

Answers (1)

Joehl
Joehl

Reputation: 3701

You should be able to change the presentation via the IsPresented property. The problem with your attempt is, that you create a new MasterDetailpage instead of using the active one.

Check if the current mainpage is a MasterDetailPage and change the presentation there:

if (Application.Current.MainPage is MasterDetailPage mdp)
{
    mdp.IsPresented = true;
}

Edit / important hint

The above solution works only, if the current Mainpage is a MasterDetailPage. Otherwise you are not able to show the menu from the page.

For a custom logic / custom slide-in/out menu, checkout the Nuget-Package "SlideOverKit".

Upvotes: 3

Related Questions