C# 无法使用转换将MvvMCross 6.x iOS颜色绑定到MvxColor
我是MvvMCross的新手,在iOS中将视图模型mvx属性绑定到背景色时遇到了一个问题。我从零开始设置了自己的项目,但为了确认它不是设置中的内容,我使用MVXSCAFolding创建了一个新项目 我得到的错误是:C# 无法使用转换将MvvMCross 6.x iOS颜色绑定到MvxColor,c#,xamarin,xamarin.ios,mvvmcross,C#,Xamarin,Xamarin.ios,Mvvmcross,我是MvvMCross的新手,在iOS中将视图模型mvx属性绑定到背景色时遇到了一个问题。我从零开始设置了自己的项目,但为了确认它不是设置中的内容,我使用MVXSCAFolding创建了一个新项目 我得到的错误是: [ERROR] (MvxBind) Problem seen during binding execution for binding TintColor for Colour - problem ArgumentException: Object of type 'MvvmC
[ERROR] (MvxBind) Problem seen during binding execution for binding
TintColor for Colour - problem ArgumentException: Object of type
'MvvmCross.UI.MvxColor' cannot be converted to type 'UIKit.UIColor'.
视图模型:
using MvvmCross.UI;
namespace BindingTests.Core.ViewModels.Main
{
public class MainViewModel : BaseViewModel
{
public MvxColor Colour { get { return MvxColors.AliceBlue; }}
}
}
看法
使用系统;
使用MvvmCross.Platforms.Ios.Presenters.Attributes;
使用MvvmCross.Platforms.Ios.Views;
使用BindingTests.Core.ViewModels.Main;
使用MvvmCross.Binding.BindingContext;
命名空间BindingTests.iOS.Views.Main
{
[MvxFromStoryboard(名称(MainViewController))]
[MvxRootPresentation(WrapInNavigationController=true)]
公共部分类MainViewController:BaseViewController
{
公共主视图控制器(IntPtr句柄):基本(句柄)
{
var set=this.CreateBindingSet();
set.Bind(LabelWelcome).For(l=>l.BackgroundColor).To(vm=>vm.color).WithConversion(“NativeColor”);
set.Apply();
}
}
}
有人有什么想法吗?我被难住了。
高声欢呼
忘了提一下,MvvmCross 5.x可以很好地实现这一点。MvvmCross 6提供了一种注册插件的新机制 我们在it方面遇到了两种问题: 1) 我们在发布之前没有发现的一个问题是,框架现在假设插件程序集在注册时将被加载。不幸的是,我们无法保证(程序集通常不会由运行时加载,除非它们被显式使用) 2) 链接器以前不是问题,因为框架有引导文件,确保代码不会被删除。我们在最重要的类上添加了
Preserve
属性,但显然这还不够
在我写这个答案的时候,我们正在开发一个新的实现,您可以跟踪状态
作为一种解决方法(并且为了实际回答这个问题),您可以将这一行添加到iOS上的
LinkerPleaseInclude
文件中(具体使用哪种方法并不重要):var converter=new MvxNativeColorValueConverter()代码>您是否在当前项目上安装了?是的,已安装中的插件。我可以很好地使用MvxColor。这只是转换。我忘了提到,使用MvvMCross 5.7这一点很好。请尝试将这一行添加到iOS上的LinkerPleaseInclude文件中(具体使用哪种方法并不重要):var converter=new MvxNativeColorValueConverter()代码>@nmilcoff,效果很好。非常感谢
using System;
using MvvmCross.Platforms.Ios.Presenters.Attributes;
using MvvmCross.Platforms.Ios.Views;
using BindingTests.Core.ViewModels.Main;
using MvvmCross.Binding.BindingContext;
namespace BindingTests.iOS.Views.Main
{
[MvxFromStoryboard(nameof(MainViewController))]
[MvxRootPresentation(WrapInNavigationController = true)]
public partial class MainViewController : BaseViewController<MainViewModel>
{
public MainViewController(IntPtr handle) : base(handle)
{
var set = this.CreateBindingSet<MainViewController, MainViewModel>();
set.Bind(LabelWelcome).For(l => l.BackgroundColor).To(vm => vm.Colour).WithConversion("NativeColor");
set.Apply();
}
}
}