Navigation Frustration

wigwig Member ✭✭
edited March 14 in Xamarin.Forms

New to Xamarin.Forms question.. I'm trying to piece together some navigation for my View Models. I have an Application ViewModel which has a Navigate method that fires an event OnViewModelChanged, passing the View Model to navigate to. All good, working well in Windows.

However on Android, I've created an AppNavigation class to handle the event, create the view, bind the viewmodel, then do the await MainPage.Navigation.PushAsync(page); - the code runs through, but after the page is navigated to a very unhelpful error message is shown: "Unhandled Exception: System.InvalidCastException: Specified cast is not valid."

The initial page is shown, using the same mechanism, with out a problem (but this is not triggered through one of the view models) and I've tried various views as the initial page and they all load fine - but every time I navigate to the second page I get the error.

Anything I'm doing wrong? Is this the right approach? Any suggestion on how to debug further?

Posts

  • wigwig Member ✭✭
    edited March 14

    BTW, Using Visual Studio 2019 and Xamarin.Forms 3.6 if that has any bearing...

  • RHudsonRHudson CAMember ✭✭✭

    Can you show your code?

    It sounds like you may be overcomplicating things.

  • wigwig Member ✭✭

    OK, delving deeper, with a process of elimination, it would appear that my property of a collection of viewmodels (which gets added to during navigation) is causing the error when bound to in the previous view. What can cause this error (that doesn't happen in windows)? I suppose I better strip back my view model piece by piece to track it down...

Sign In or Register to comment.