gpt4 book ai didi

xamarin - 如何修复 Android Xamarin.Forms 中的渲染器警告

转载 作者:行者123 更新时间:2023-12-03 05:11:02 24 4
gpt4 key购买 nike

Warning CS0618: 'PickerRenderer.PickerRenderer()' is obsolete: 'This constructor is obsolete as of version 2.5. Please use PickerRenderer(Context) instead.

此警告不仅出现在选择器渲染器中,所有渲染器(Entry、DatePicker、StackLayout 渲染器)都显示此警告。我的 Picker 自定义渲染器是这样的,

 public class BorderlessPickerRenderer : PickerRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Picker> e)
{
base.OnElementChanged(e);
var picker = e.NewElement;
if (Control != null)
{
Control.Background = null;

Control.SetTextSize(Android.Util.ComplexUnitType.Pt, 8);

Control.SetTextColor(Android.Graphics.Color.ParseColor("#141414"));
}
}
}

最佳答案

有一个新的 .ctor 用于 Xamarin.Forms (2.5+) 基于 Android 的渲染器,它接受基于 Android 的上下文。为了支持 native 嵌入,旧的无参数构造函数已被标记为过时。

将其添加到您的渲染器:

public BorderlessPickerRenderer(Context context) : base(context)
{
}

关于xamarin - 如何修复 Android Xamarin.Forms 中的渲染器警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47988091/

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