gpt4 book ai didi

c# - Xamarin - Customrenderer 出现 2 个错误

转载 作者:行者123 更新时间:2023-11-29 19:55:31 25 4
gpt4 key购买 nike

因此,我在位于 SalesKicker.Droid 中的 CustomSwitchRenderer 类中遇到了这些错误。以下是错误:

OnElementCHanged(ElementChangedEventArgs e): no suitable method found to override

Android.Widget.Switch cannot be used as typ parameter 'TElement' in the genericc type or method ElementChangedEventArgs' There is no implicit referencee conversion from Widget.Switch to Forms.Element

我很困惑,因为这以前有效,但我不知道我在这里做错了什么。这是我的类(class):

public class CustomSwitchRenderer : SwitchRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Switch> e)
{
base.OnElementChanged(e);

if (Control != null)
{
Control.TextOn = "AAN";
Control.TextOff = "UIT";

Color colorON = Color.Green;
Color colorOFF = Color.Red;

Control.SetTextColor(Color.Black);

StateListDrawable drawable = new StateListDrawable();

drawable.AddState(new int[]
{
Android.Resource.Attribute.StateChecked
}, new ColorDrawable(colorON));
drawable.AddState(new int[]
{

}, new ColorDrawable(colorOFF));

Control.ThumbDrawable = drawable;
}
}
}

是的,我还添加了这一行:

using Switch = Android.Widget.Switch

当然还有这个:

[assembly:ExportRenderer(typeof(Switch), typeof(CustomSwitchRenderer))]

谁能告诉我我做错了什么?

最佳答案

您需要using Switch = Xamarin.Forms.Switch 而不是using Switch = Android.Widget.Switch

关于c# - Xamarin - Customrenderer 出现 2 个错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36768005/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com