在设置MvvmCross 6.0时我做错了什么?

时间:2018-05-01 05:14:13

标签: xamarin xamarin.forms xamarin.android mvvmcross

我是MvvmCross 6.0和Xamarin的新手。

我正在尝试关注tutorial here that for MvvmCrosss 5.5

我按照说明,

  1. 将App.xaml创建为MvxFormsApplication
  2.     <?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()
    2. 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
      2. public class MainPageViewModel : MvxViewModel
            {
            }
        
        1. 查看使用类型MainPageViewModel
        2. 创建的MvxContentPage

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

          1. 删除了MainActivity并创建了一个名为MainApplication.cs的文件,如下所示
          2. [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<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();
                }
            

            然而,我启动了应用程序,它给了我一个空例外说&#34;捆绑&#34;在OnCreated方法中,参数为null。

            P.S。本教程提到创建Setup.cs,但我不知道如何通过代码运行Setup.cs。我看不到它引用它的位置。

1 个答案:

答案 0 :(得分:3)

在使用v 6.0时,我不确定为什么要查看5.5版本的教程。请尝试关注同一作者的step by step guide,但版本6.0

您可能还想从他的GitHub repo下载Nick的样本,以检查其运作方式。