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

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

问题描述

我是MvvmCross 6.0和Xamarin的新手.

I am new to MvvmCross 6.0 and Xamarin.

我正在尝试遵循我按照了说明

  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()

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继承了MvxViewModel

public class MainPageViewModel : MvxViewModel
    {
    }

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

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

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

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

ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)] 公共类MainActivity:MvxFormsAppCompatActivity { 受保护的重写void OnCreate(捆绑包) { TabLayoutResource = Resource.Layout.Tabbar; ToolbarResource = Resource.Layout.Toolbar;

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();
    }

无论我启动该应用程序是什么,它都给我带来了空异常,即OnCreated方法中的"bundle"参数为空.

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

P.S.本教程提到要创建Setup.cs,但是我不知道如何通过代码运行Setup.cs....我看不到在哪里引用它.

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.

推荐答案

我不确定为什么在使用v 6.0时为什么要查看5.5版教程.尝试遵循

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

您可能还想从Nick的 GitHub存储库中下载样本,以检查其工作方式.

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

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

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