【问题标题】:Binding in skiasharp xamarin forms以skiasharp xamarin 形式绑定
【发布时间】:2018-02-03 17:29:26
【问题描述】:

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

【问题讨论】:

    标签: c# binding xamarin.forms skiasharp


    【解决方案1】:

    感谢来自 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

    【讨论】:

      猜你喜欢
      • 2022-06-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-06
      • 2019-11-17
      • 1970-01-01
      • 2017-01-11
      • 1970-01-01
      相关资源
      最近更新 更多