我在设置 MvvmCross 6.0 时做错了什么? [英] What did I do wrong on setting up MvvmCross 6.0?

查看:24
本文介绍了我在设置 MvvmCross 6.0 时做错了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 MvvmCross 6.0 和 Xamarin 的新手.

我正在尝试遵循 这里是 MvvmCrosss 5.5 的教程

我按照说明操作,

  1. 将 App.xaml 创建为 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 作为 MvxApplication 并运行 RegisterAppStart();在我覆盖的 Initialize() 中

<块引用>

公共类 CoreApp : MvxApplication{公共覆盖无效初始化(){可创建类型().EndingWith("服务").AsInterfaces().RegisterAsLazySingleton();可创建类型().EndingWith("客户").AsInterfaces().RegisterAsLazySingleton();//注册appstart对象RegisterAppStart();}}

  1. MainPageViewModel 继承 MvxViewModel

<块引用>

公共类 MainPageViewModel : MvxViewModel{}

  1. 创建为 MvxContentPage 且类型为 MainPageViewModel 的视图

  1. 删除了 MainActivity 并创建了一个名为 MainApplication.cs 的文件,如下所示

<块引用>

[Activity(Label = "MvvmcrossGettingStarted", Icon = "@drawable/icon", Theme = "@style/MainTheme", MainLauncher = true,

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

 base.OnCreate(bundle);var startup = Mvx.Resolve();启动.开始();InitializeForms(bundle);}}公共类设置:MvxFormsAndroidSetup{公共设置():基础(){}受保护的覆盖 IEnumerableAndroidViewAssemblies =>new List(base.AndroidViewAssemblies.Union(new[] { typeof(App).GetTypeInfo().Assembly }).Except(new[] { this.GetType().Assembly }));受保护的覆盖应用程序 CreateFormsApplication(){返回新的应用程序();}受保护的覆盖 IMvxApplication CreateApp() =>新的核心应用程序();}

然而,我启动了应用程序,它给了我空异常,说 OnCreated 方法中的bundle"参数为空.

附言该教程提到创建 Setup.cs,但我不知道该 Setup.cs 是如何由代码运行的....我看不到引用它的地方.

解决方案

我不知道您为什么在使用 v 6.0 时查看 5.5 版教程.尝试遵循 分步指南,来自同一作者,但适用于 6.0 版

您可能还想从他的 GitHub 存储库下载 Nick 的示例,检查事情是如何运作的.

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.

解决方案

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.

这篇关于我在设置 MvvmCross 6.0 时做错了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆