Forum Xamarin Xamarin.Forms

Is there a MVVM way to bind MasterDetailPage Detail?

WinterCloudWinterCloud GBMember ✭✭✭
edited April 2017 in Xamarin.Forms

I got multiple details pages, they are different and have different page models.

All the example I can find is using event, itemselected of the Master Page Menu, and just create a page based on the page type registered with the menu item. Like here:
https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/navigation/master-detail-page/

Is there a MVVM way, so I can bind Detail, and display correct detail page by binding the detail page model.

I'm not using any MVVM package, just native Xamarin.Forms code.

I'm not sure what the detail page model type is going to be, a page model base or object I guess.

Please advise. Thanks in advance.

For example:

`

    class MasterPageModel 
    {
        private object _detailPage;

        public MasterHomePageModel MasterMenuPage { get; set; }

        public object DetailPage
        {
            get { return _detailPage; }
            set { SetProperty( ref _detailPage, value ); }
        }
    }

`

Best Answer

Answers

  • WinterCloudWinterCloud GBMember ✭✭✭

    @mikeacosta said:
    Not sure if this is what you're after, but I just populate the menu ListView with view model instances, with a string property for each page class


    and then do the item selected like this


    HTH

    Thanks for the reply, I believe this will work.

    I've seen this approach somewhere, as my project can't use magic strings and I'm trying to stay away from reflection, I didn't use this approach.

  • mikeacostamikeacosta USUniversity ✭✭✭

    Yeah, probably an enum for pages would be a little better.

  • PsienaertPsienaert Member ✭✭

    Why is the answer greyed out?

    I was looking for the same solution.

Sign In or Register to comment.