King Chan
King Chan

Reputation: 4302

What did I do wrong on setting up MvvmCross 6.0?

I am new to MvvmCross 6.0 and Xamarin.

I am trying to follow the tutorial here that for MvvmCrosss 5.5

I followed the explanation,

  1. Created App.xaml as MvxFormsApplication
    <?xml version="1.0" encoding="utf-8" ?>
<core:MvxFormsApplication xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:core="clr-namespace:MvvmCross.Forms.Core;assembly=MvvmCross.Forms"
             x:Class="App3.App">
</core:MvxFormsApplication>
  1. CoreApp.cs as MvxApplication and runs RegisterAppStart(); in my overrided Initialize()
public class CoreApp : MvxApplication
    {

        public override void Initialize()
        {
            CreatableTypes()
                .EndingWith("Service")
                .AsInterfaces()
                .RegisterAsLazySingleton();

            CreatableTypes()
                .EndingWith("Client")
                .AsInterfaces()
                .RegisterAsLazySingleton();

            // register the appstart object
            RegisterAppStart<MainPageViewModel>();
        }
    }
  1. MainPageViewModel to inherited MvxViewModel
public class MainPageViewModel : MvxViewModel
    {
    }
  1. View that created as MvxContentPage with type MainPageViewModel

<Label Text="Welcome to Xamarin.Forms!" 
       VerticalOptions="Center" 
       HorizontalOptions="Center" />

  1. Removed MainActivity and created a file called MainApplication.cs as follow
[Activity(Label = "MvvmcrossGettingStarted", Icon = "@drawable/icon", Theme = "@style/MainTheme", MainLauncher = true,

ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)] public class MainActivity : MvxFormsAppCompatActivity { protected override void OnCreate(Bundle bundle) { TabLayoutResource = Resource.Layout.Tabbar; ToolbarResource = Resource.Layout.Toolbar;

            base.OnCreate(bundle);

            var startup = Mvx.Resolve<IMvxAppStart>();
            startup.Start();
            InitializeForms(bundle);

        }
    }


    public class Setup : MvxFormsAndroidSetup
    {
        public Setup():base()
        {

        }

        protected override IEnumerable<Assembly> AndroidViewAssemblies => new List<Assembly>(base.AndroidViewAssemblies
            .Union(new[] { typeof(App).GetTypeInfo().Assembly })
            .Except(new[] { this.GetType().Assembly })
        );

        protected override Application CreateFormsApplication()
        {
            return new App();
        }


        protected override IMvxApplication CreateApp() => new CoreApp();
    }

However what I started the app, its gives me null exception saying "bundle" parameter is null in OnCreated method.

P.S. The tutorial mention to create the Setup.cs, but I have no idea how does that Setup.cs being run by the code.... I see no where that is referencing it.

Upvotes: 1

Views: 871

Answers (1)

Mikolaj Kieres
Mikolaj Kieres

Reputation: 4405

I'm not sure why you're looking at the version 5.5 tutorial while working with v 6.0. Try following step by step guide, from same author, but for version 6.0

You might also want to download Nick's sample, from his GitHub repo, to check how things work.

Upvotes: 3

Related Questions