James
James

Reputation: 223

Xamarin Prism MasterDetailPage.IsPresented from child ViewModel

Does anyone have a clue on how to control IsPresented property from a child view model?

I'm implementing a custom NavBar where I want to simulate the Hamburger icon behavior so my child page on load has

NavigationPage.SetHasNavigationBar(this, false);

which hides the navigation par.

Inside Xaml file I have a button which I want to bind to a PropertyCommand of child viewmodel and show Master page, basically somehow to call Master's IsPresented.

Thanks.

Upvotes: 2

Views: 1054

Answers (1)

skar
skar

Reputation: 179

There are a couple of ways to go about it.

The way I would do it would be to use MVVM and use an interface to access the 'presenting the Master page' functionality where its needed.

 public interface ICustomMasterDetail
 {
      void SetMasterPresented(bool isPresented);
 }

Now extend on the MasterDetailPage and also implement the above interface

public class CustomMasterDetail : MasterDetailPage, IRootMasterDetail
{
     public CustomMasterDetail() : base()
     {
        //constructor code
     }

     public void SetMasterPresented(bool isPresented)
     {
         IsPresented = isPresented;
     }
}

Using using an IoC container to register and resolve the interface will let you use its functionality from where ever you want.

The other solution would be to just use a static variable to store the instance of your MasterDetailPage and access that directly to change the IsPresented property

Upvotes: 1

Related Questions