Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Fix Renderer Warnings in Android Xamarin.Forms

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

This Warning is not only in picker renderer all renderers(Entry, DatePicker, StackLayout Renderer) are showing this warning. My custom renderer for Picker is like this,

 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"));
            }
        }
    }
like image 615
Karthick Avatar asked Dec 27 '17 07:12

Karthick


2 Answers

There is a new .ctor for Xamarin.Forms (2.5+) Android-based renderers that accepts an Android-based context. The older parameterless constructor have been marked obsolete in order to support native embedding.

Add this to your renderer:

public BorderlessPickerRenderer(Context context) : base(context)
{
}
like image 119
SushiHangover Avatar answered Sep 19 '22 08:09

SushiHangover


According to 2.5.0 release notes you should add a constructor the next way:

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

In addition there is a dedicated thread on official Xamarin forums on this topic.

like image 37
EvZ Avatar answered Sep 20 '22 08:09

EvZ