本文介绍了将MvvmCross升级到5.2会在CustomAndroidPresenter上显示错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
将MvvmCross从5.1升级到5.2后,我的CustomAndroidPresenter.cs抛出构建错误.是什么原因造成的?
After upgrading MvvmCross from 5.1 to 5.2 , my CustomAndroidPresenter.cs is throwing a build error. What is causing this?
CustomAndroidPresenter.cs:
CustomAndroidPresenter.cs:
namespace TestPrjDroid
{
public class CustomAndroidPresenter : MvxAndroidViewPresenter
{
public override void Show(MvxViewModelRequest request)
{
if (request != null && request.PresentationValues != null)
{
if (request.PresentationValues.ContainsKey("MyCustomFlag"))
{
// Get intent from request and set flags to clear backstack.
var intent = base.CreateIntentForRequest(request);
intent.AddFlags(ActivityFlags.ClearTask | ActivityFlags.ClearTop | ActivityFlags.NewTask);
base.Show(intent);
return;
}
}
base.Show(request);
}
}
}
错误:
参数1:无法从"Android.Content.Intent"转换为 'MvvmCross.Core.ViewModels.MvxViewModelRequest'
Argument 1: cannot convert from 'Android.Content.Intent' to 'MvvmCross.Core.ViewModels.MvxViewModelRequest'
推荐答案
您需要为MvxAndroidViewPresenter(IEnumerable)
添加构造函数:
You need to add a constructor for MvxAndroidViewPresenter(IEnumerable)
:
public class CustomAndroidPresenter : MvxAndroidViewPresenter
{
public CustomAndroidPresenter(IEnumerable<Assembly> androidViewAssemblies) : base(androidViewAssemblies)
{
}
public override void Show(MvxViewModelRequest request)
{
if (request != null && request.PresentationValues != null)
{
if (request.PresentationValues.ContainsKey("MyCustomFlag"))
{
// Get intent from request and set flags to clear backstack.
var intent = base.CreateIntentForRequest(request);
intent.AddFlags(ActivityFlags.ClearTask | ActivityFlags.ClearTop | ActivityFlags.NewTask);
base.ShowIntent(intent);
return;
}
}
base.Show(request);
}
}
这篇关于将MvvmCross升级到5.2会在CustomAndroidPresenter上显示错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!