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,
- 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>
- 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>(); } }
- MainPageViewModel to inherited MvxViewModel
public class MainPageViewModel : MvxViewModel { }
- View that created as MvxContentPage with type MainPageViewModel
<Label Text="Welcome to Xamarin.Forms!"
VerticalOptions="Center"
HorizontalOptions="Center" />
- 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.