【发布时间】:2018-02-03 17:29:26
【问题描述】:
我想绑定 skpaint 颜色属性,因为skiasharp 表单库没有内置绑定。有人可以展示如何实现这一点,或者至少为我指明一个方向。
【问题讨论】:
标签: c# binding xamarin.forms skiasharp
我想绑定 skpaint 颜色属性,因为skiasharp 表单库没有内置绑定。有人可以展示如何实现这一点,或者至少为我指明一个方向。
【问题讨论】:
标签: c# binding xamarin.forms skiasharp
感谢来自 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
【讨论】: