我创建了Setup:MvxAndroidSetup
public class Setup : MvxAndroidSetup
{
public Setup(Context applicationContext)
: base(applicationContext)
{
}
protected override IMvxApplication CreateApp()
{
return new App();
}
protected override IEnumerable<Assembly> AndroidViewAssemblies =>
new List<Assembly>(base.AndroidViewAssemblies)
{
typeof(Android.Support.Design.Widget.NavigationView).Assembly,
typeof(Android.Support.Design.Widget.FloatingActionButton).Assembly,
typeof(Android.Support.V7.Widget.Toolbar).Assembly,
typeof(Android.Support.V4.Widget.DrawerLayout).Assembly,
typeof(Android.Support.V4.View.ViewPager).Assembly,
typeof(MvvmCross.Droid.Support.V7.RecyclerView.MvxRecyclerView).Assembly
};
/// <summary>
/// This is very important to override. The default view presenter does not know how to show fragments!
/// </summary>
protected override IMvxAndroidViewPresenter CreateViewPresenter()
{
var mvxFragmentsPresenter = new MvxFragmentsPresenter(AndroidViewAssemblies);
Mvx.RegisterSingleton<IMvxAndroidViewPresenter>(mvxFragmentsPresenter);
return mvxFragmentsPresenter;
}
}
我使用的是mvvmscross版本5.2.1 我在行代码中有问题var mvxFragmentsPresenter = new MvxFragmentsPresenter(AndroidViewAssemblies);.当运行项目时 Mac中的Visual Studio 2017通知:
System.MissingMethodException: Method 'MvvmCross.Droid.Views.MvxAndroidViewPresenter..ctor' not found.
at VietOrder.Droid.Setup.CreateViewPresenter () [0x00001] in /Volumes/Data/Dev/VietOrder/Xamarin/VietOrder/VietOrder.Droid/Setup.cs:46
at MvvmCross.Droid.Platform.MvxAndroidSetup.CreateViewDispatcher () [0x00000] in C:\projects\mvvmcross\MvvmCross\Droid\Droid\Platform\MvxAndroidSetup.cs:124
at MvvmCross.Core.Platform.MvxSetup.InitializeViewDispatcher () [0x00000] in C:\projects\mvvmcross\MvvmCross\Core\Core\Platform\MvxSetup.cs:260
at MvvmCross.Core.Platform.MvxSetup.InitializeSecondary () [0x000f8] in C:\projects\mvvmcross\MvvmCross\Core\Core\Platform\MvxSetup.cs:91
at MvvmCross.Droid.Platform.MvxAndroidSetupSingleton.<InitializeFromSplashScreen>b__7_0 (System.Object ignored) [0x00000] in C:\projects\mvvmcross\MvvmCross\Droid\Droid\Platform\MvxAndroidSetupSingleton.cs:92
at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context (System.Object state) [0x00007] in <896ad1d315ca4ba7b117efb8dacaedcf>:0
at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00071] in <896ad1d315ca4ba7b117efb8dacaedcf>:0
at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <896ad1d315ca4ba7b117efb8dacaedcf>:0
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem () [0x00021] in <896ad1d315ca4ba7b117efb8dacaedcf>:0
at System.Threading.ThreadPoolWorkQueue.Dispatch () [0x00074] in <896ad1d315ca4ba7b117efb8dacaedcf>:0
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () [0x00000] in <896ad1d315ca4ba7b117efb8dacaedcf>:0
谢谢!
答案 0 :(得分:0)
我想我已经解决了这个问题,但是从4.4.0版本升级到最新的MvvmCross版本(5.3.1)已经过了很长一段路。我将确定升级所需的步骤。应该注意的是,在此之前,我已将所有Xamarin和其他软件包更新为最新且最好的,并确保项目编译和运行。此外,我更新了Xamarin本身到4.7.10.22,它带来了对Android 8.0的支持(我还没有iOS前端)。这里是我更新到MvvmCross 5.3.1的步骤:
现在回答您的问题,我将我的Setup类更改为 MvxAppCompatSetup 的子类。调用 MvxAppCompatSetup 更改为简单创建新的MvxAppCompatViewPresenter()(见下文)以及删除导入MvvmCross.Droid.Shared.Presenter:
protected override IMvxAndroidViewPresenter CreateViewPresenter()
{
return new MvxAppCompatViewPresenter(AndroidViewAssemblies);
}
此外,由于我使用了一些片段,我需要将它们的属性从 MvxFragment 更改为 MvxFragmentPresentation 。最后一项更改是将我的主要Activity从子类 MvxCachingFragmentCompatActivity 更改为子类 MvxAppCompatActivity 。所有这些对我来说都很有用,希望对你有帮助。
P.S。我仍然需要更改导航以符合新的NavigationService。