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