MvvmCross MvxColor无法转换为UI颜色

时间:2017-10-07 14:10:07

标签: c# ios xamarin.ios mvvmcross

我有一个带有lavel的Xamarin IOS应用程序,我想将文本的颜色绑定到MvxColor类型的属性:

    public MvxColor ColorStateRequestLoginCode
    {
        get => colorStateRequestLoginCode;
        set
        {
            if (colorStateRequestLoginCode == value) return;

            colorStateRequestLoginCode = value;
            RaisePropertyChanged();
        }
    }

        bindingSet.Bind(labelStatusRequestCode)
                  .For(lbl => lbl.TextColor)
                  .To(vm => vm.ColorStateRequestLoginCode)
                  .WithConversion("NativeColor");

我添加了颜色插件并将其添加到插件加载器中:

    protected override void AddPluginsLoaders(MvxLoaderPluginRegistry registry)
    {
        base.AddPluginsLoaders(registry);
        registry.FindLoader(typeof(MvvmCross.Plugins.Color.iOS.Plugin));
    }

但是当调用视图时,我在输出中得到了这个:

MvxBind:Error: 64.27 Problem seen during binding execution for binding TextColor for ColorStateRequestLoginCode - problem ArgumentException: Object of type 'MvvmCross.Platform.UI.MvxColor' cannot be converted to type 'UIKit.UIColor'.
      at System.RuntimeType.CheckValue (System.Object value, System.Reflection.Binder binder, System.Globalization.CultureInfo culture, System.Reflection.BindingFlags invokeAttr) [0x00056] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.0.0.0/src/mono/mcs/class/corlib/ReferenceSources/RuntimeType.cs:195 
  at System.Reflection.MonoMethod.ConvertValues (System.Reflection.Binder binder, System.Object[] args, System.Reflection.ParameterInfo[] pinfo, System.Globalization.CultureInfo culture, System.Reflection.BindingFlags invokeAttr) [0x00069] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.0.0.0/src/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:345 
  at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00011] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.0.0.0/src/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:293 
  at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.0.0.0/src/mono/mcs/class/referencesource/mscorlib/system/reflection/methodbase.cs:229 
  at MvvmCross.Binding.Bindings.Target.MvxPropertyInfoTargetBinding.SetValueImpl (System.Object target, System.Object value) [0x0000d] in C:\projects\mvvmcross\MvvmCross\Core\Binding\Bindings\Target\MvxPropertyInfoTargetBinding.cs:48 
  at MvvmCross.Binding.Bindings.Target.MvxConvertingTargetBinding.SetValue (System.Object value) [0x00093] in C:\projects\mvvmcross\MvvmCross\Core\Binding\Bindings\Target\MvxConvertingTargetBinding.cs:65 
  at MvvmCross.Binding.Bindings.MvxFullBinding+<>c__DisplayClass24_0.<UpdateTargetFromSource>b__0 () [0x00025] in C:\projects\mvvmcross\MvvmCross\Core\Binding\Bindings\MvxFullBinding.cs:185 

我还需要做别的吗?

0 个答案:

没有答案