Autofac Library Master Detail crash with Invalid Cast Exception

MudiyalaMudiyala USMember ✭✭
edited April 2016 in Xamarin.Forms

I am using Autofac and able to navigate with viewmodel based approach for initial screens.
At certain point say (Login), I need to show master detail screen. I have added below code to reset MainPage

Application.Current.MainPage = _viewFactory.Resolve ();

In the RootPage (which MasterDetailPage), I am setting menu and detail pages like below

Master = viewFactory.Resolve ();
MenuPage page = (MenuPage)Master;
Detail = new NavigationPage (viewFactory.Resolve());

I was able to show page but couldn't able to access _navigation or _dialogue services. Also not sure how I am going to drill down in each detail page.

If I access _navigation or _dialogue then app crashing with InValidCastException.

Please help me regarding whether I am following properly with switching from VM based approach to MasterDetail.

Thank you.

Best Answer

Answers

  • AltafLatheefAltafLatheef USMember

    Hey @Mudiyala can you please share that part of code mentioned above. I have been trying to implement MasterDetailPage using Autofac. Do i need to mention anything inside App class or in bootstrapper?

  • MudiyalaMudiyala USMember ✭✭

    Please check below link:
    https://xamarinforms.wordpress.com/2015/01/13/creating-a-xamarin-forms-app-part-12-extending-the-user-interface/

    In Bootstrapper, I did configure as below. Rootpage is masterdetail

    var mainPage = viewFactory.Resolve<RootPageViewModel>();
    _application.MainPage = mainPage;
    
Sign In or Register to comment.