0

我想绑定 skpaint 颜色属性,因为skiasharp 表单库没有内置绑定。有人可以展示如何实现这一点或至少为我指明一个方向。

4

1 回答 1

0

感谢 xamarin 论坛的 AlexP,我可以将自己的可绑定属性添加到任何控件,这非常简单

 public class BindableSKCanvasView : SKCanvasView
    {

        public static readonly BindableProperty ColorProperty =
                BindableProperty.Create("Color", typeof(SKColor), typeof(BindableSKCanvasView),defaultValue:SKColors.Black, defaultBindingMode: BindingMode.TwoWay, propertyChanged: RedrawCanvas);

        public SKColor Color
        {
            get => (SKColor)GetValue(ColorProperty);
            set => SetValue(ColorProperty, value);
        }


        private static void RedrawCanvas(BindableObject bindable, object oldvalue, object newvalue)
        {
            BindableSKCanvasView bindableCanvas = bindable as BindableSKCanvasView;
        bindableCanvas.InvalidateSurface();
        }
    }

这是供参考的论坛链接

https://forums.xamarin.com/discussion/122312/binding-in-skiasharp-xamarin-forms

于 2018-02-24T12:42:12.483 回答