Search code examples
xamarinmvvmcross

MvvmCross - navigation with custom objects


I have followed the steps in this link Passing complex navigation parameters with MvvmCross ShowViewModel

i implemented an instance of the IMvxJsonConverter, and registered it. this is my code for my view model

 public class AccountDetailsViewModel : BaseViewModel<AccountDetailsNav>
{


    private readonly Repository.AccountsRepository _accounts;
    Account _fullAccount;
    public AccountDetailsViewModel(Repository.AccountsRepository accounts)
    {
        _accounts = accounts;
    }

    protected override void RealInit(AccountDetailsNav parameter)
    {
        //stuff
    }

I have tried simple types by just passing thru strings , this is the code i use to navigate to to the viewmodel

   Mvx.RegisterSingleton<Repository.AccountsRepository>(() =>
        {
            return _accounts;
        });


        ShowViewModel<AccountDetailsViewModel>(nav);

But it never ever seems to arrive in my view model methods or populates my data, and i cannot for the life of me figure out why. the data is serialized fine , and i have even tried blank constructors to no avail .. i just cannot figure out why its not hitting the realinit


Solution

  • K i found the problem , when adding a new view i failed to remove this method on the code behind of the view, and as such was causing my viewmodel to be null and never hitting my breakpoints

        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.
        /// This parameter is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }