简体   繁体   中英

How can I call a method from my bindings and override in iOS?

I have this class:

public class ExtSwitch : Switch
{
    public static readonly 
        BindableProperty SwitchOutsideOvalColorProperty = 
        BindableProperty.Create(nameof(SwitchOutsideOvalColor), 
        typeof(Color), 
        typeof(ExtSwitch), 
        Color.Default, 
        propertyChanged: HandleOutsidePropertyChanged);
    public Color SwitchOutsideOvalColor { 
        get => (Color)GetValue(SwitchOutsideOvalColorProperty); 
        set => SetValue(SwitchOutsideOvalColorProperty, value); }

    public void HandleOutsidePropertyChanged(BindableObject bindable, object oldValue, object newValue)
    {
        var a = 99;
    }
}

and I am trying to create an iOS version that I would like to respond to the HandleOutsidePropertyChanged(). I tried this:

[assembly: ExportRenderer(typeof(ExtSwitch), typeof(ExtSwitchRenderer))]
namespace Japanese.iOS
{
    class ExtSwitchRenderer : SwitchRenderer
    {

       public override void HandleOutsidePropertyChanged(BindableObject bindable, object oldValue, object newValue)
       {
          var a = 99;
       }

    }
}

But I am getting an error saying no suitable method found to override.

HandleOutsidePropertyChanged是ExtSwitch的一种方法,ExtSwitchRenderer继承自SwitchRenderer。

Instead of:

public void HandleOutsidePropertyChanged(BindableObject bindable, object oldValue, object newValue)
{
    var a = 99;
}

You need to do this.

public void HandleOutsidePropertyChanged(BindableObject bindable, Color oldValue, Color newValue)
{
    var a = 99;
}

Then you can override.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM