Force redraw of Xamarin.Forms View with custom renderer

前端 未结 2 682
小鲜肉
小鲜肉 2021-02-13 18:16

I have a visual element MyButton with a custom renderer implemented for iOS.

Shared:

namespace RendererTest
{
    public class MyButton: But         


        
2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-13 18:52

    First, turn you BoundaryColor into a bindable property. That's not required, firing INPC event is enough, but then you can bind to it:

    public static readonly BindableProperty BoundaryColorProperty =
        BindableProperty.Create ("BoundaryColor", typeof(Color), typeof(MyButton), Color.Default);
    
    public Color BoundaryColor {
        get { return (Color)GetValue (BoudaryColorProperty); }
        set { SetValue (BoundaryColorProperty, value); }
    }
    

    then, in your renderer:

    protected override void OnElementPropertyChanged (object sender, PropertyChangedEventArgs e)
    {
        base.OnElementPropertyChanged (sender, e);
    
        if (e.PropertyName == MyButton.BoundaryColorProperty.PropertyName)
            SetNeedsDisplay ();
    }
    

提交回复
热议问题