C# 如何在iOS中从绑定和重写调用方法?
我有这门课:C# 如何在iOS中从绑定和重写调用方法?,c#,xamarin,xamarin.forms,C#,Xamarin,Xamarin.forms,我有这门课: public class ExtSwitch : Switch { public static readonly BindableProperty SwitchOutsideOvalColorProperty = BindableProperty.Create(nameof(SwitchOutsideOvalColor), typeof(Color), typeof(ExtSwitch),
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;
}
}
我正在尝试创建一个iOS版本,我想响应HandleOutsidePropertyChanged()。我试过这个:
[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;
}
}
}
但是我得到一个错误,说找不到合适的方法进行覆盖。HandleOutsidePropertyChanged是一个ExtSwitch方法,ExtSwitchRenderer继承自SwitchRenderer。HandleOutsidePropertyChanged是一个ExtSwitch方法,ExtSwitchRenderer继承自SwitchRenderer。而不是:
public void HandleOutsidePropertyChanged(BindableObject bindable, object oldValue, object newValue)
{
var a = 99;
}
你需要这样做
public void HandleOutsidePropertyChanged(BindableObject bindable, Color oldValue, Color newValue)
{
var a = 99;
}
然后您可以覆盖。而不是:
public void HandleOutsidePropertyChanged(BindableObject bindable, object oldValue, object newValue)
{
var a = 99;
}
你需要这样做
public void HandleOutsidePropertyChanged(BindableObject bindable, Color oldValue, Color newValue)
{
var a = 99;
}
然后你可以覆盖