【发布时间】:2018-10-20 21:09:18
【问题描述】:
我是 MvvMCross 的新手,在将我的视图模型 mvx 属性绑定到 iOS 中的背景颜色时遇到问题。我从头开始设置了自己的项目,但为了确认它不是设置中的内容,然后我使用 MvxScaffolding 创建了一个新项目。
我得到的错误是:
[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; }}
}
}
查看
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();
}
}
}
有人有什么想法吗?我难住了。 进阶干杯
忘了说,这适用于 MvvmCross 5.x
【问题讨论】:
-
您是否在当前项目中安装了MvvmCross.Plugin.Color package?
-
是的,已安装插件。我可以很好地使用 MvxColor。这只是转换。我忘了提,使用 MvvMCross 5.7 效果很好。
-
您能否尝试将此行添加到 iOS 上的 LinkerPleaseInclude 文件中(具体使用哪种方法并不重要):
var converter = new MvxNativeColorValueConverter(); -
@nmilcoff ,工作得很好。非常感谢
标签: c# xamarin xamarin.ios mvvmcross