MvvmCross - 用于Layer.BackgroundColor的MonoTouch目标绑定

时间:2014-07-23 08:55:27

标签: xamarin.ios xamarin mvvmcross

使用MvvmCross我为Layer.BackgroundColor创建了以下目标绑定(为了利用Layer.CornerRadius绘制圆圈),但我(仍然)收到错误Failed to create target binding for binding Layer.BackgroundColor for Color。< / p>

MvxUIViewLayerBackgroundColorTargetBinding.cs

public class MvxUIViewLayerBackgroundColorTargetBinding : MvxConvertingTargetBinding {
    public MvxUIViewLayerBackgroundColorTargetBinding(object target) : base (target) {}

    public override Type TargetType {
        get { return typeof(CGColor); }
    }

    protected override void SetValueImpl(object target, object value) {
        var view = (UIView) target;

        if (view == null || value == null) {
            return;
        }

        if (view.Layer == null) {
            return;
        }

        view.Layer.BackgroundColor = ((UIColor) value).CGColor;
    }
}

在Setup.cs

protected override void FillTargetFactories(IMvxTargetBindingFactoryRegistry registry) {
    base.FillTargetFactories(registry);

    registry.RegisterCustomBindingFactory<UIView>("LayerBackgroundColor", view => new MvxUIViewLayerBackgroundColorTargetBinding(view));
}

绑定

set.Bind(circle)
   .For(x => x.Layer.BackgroundColor)
   .To(x => x.Color)
   .WithConversion(new ColorNameToValueConverter(), null);

0 个答案:

没有答案