【问题标题】:How to Fix Renderer Warnings in Android Xamarin.Forms如何修复 Android Xamarin.Forms 中的渲染器警告
【发布时间】:2019-01-10 00:14:51
【问题描述】:

警告 CS0618:“PickerRenderer.PickerRenderer()”已过时:“此 从 2.5 版开始,构造函数已过时。请用 取而代之的是 PickerRenderer(Context)。

此警告不仅在选取器渲染器中,所有渲染器(Entry、DatePicker、StackLayout Renderer)都显示此警告。我的 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"));
            }
        }
    }

【问题讨论】:

    标签: xamarin xamarin.forms xamarin.android


    【解决方案1】:

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

    将此添加到您的渲染器中:

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

    【讨论】:

      【解决方案2】:

      根据2.5.0 release notes,您应该按以下方式添加构造函数:

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

      此外,在 Xamarin 官方论坛上还有一个关于此主题的 dedicated thread

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-01-05
        • 2020-05-12
        • 2019-04-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多