No constructor found for Xamarin.Forms.Platform.Android.LabelRenderer (xamarin forms)

前端 未结 1 1780
没有蜡笔的小新
没有蜡笔的小新 2021-01-17 13:30

I have a list of image in my xaml on pcl project when I test my app in my samsumg galaxy s5 device I do this: I enter in the page of the list, then I press the back button o

1条回答
  •  再見小時候
    2021-01-17 14:12

    You've named your class LabelRenderer, which already exists in the Xamarin.Forms.Platform.Android namespace.

    In the assembly attribute, typeof(LabelRenderer) is equivalent to typeof(Xamarin.Forms.Platform.Android.LabelRenderer), but we need it to be typeof(neoFly_Montana.Droid.LabelRenderer).

    An easy way to avoid these namespace conflicts going forward is to use a unique class name, like NeoFly_MontanaLabelRenderer.

    And when using Xamarin.Forms v2.5+, we need to use an overloaded Constructor, which I've added below.

    For Xamarin.Forms v2.4 (and below)

    using System;
    
    using Android.Runtime;
    
    using Xamarin.Forms;
    using Xamarin.Forms.Platform.Android;
    
    using neoFly_Montana.Droid;
    
    [assembly: ExportRenderer(typeof(Xamarin.Forms.Label), typeof(NeoFly_MontanaLabelRenderer))]
    namespace neoFly_Montana.Droid
    {
        public class NeoFly_MontanaLabelRenderer : Xamarin.Forms.Platform.Android.LabelRenderer
        {
    
        }
    }
    

    For Xamarin.Forms v2.5+

    using System;
    
    using Android.Runtime;
    
    using Xamarin.Forms;
    using Xamarin.Forms.Platform.Android;
    
    using neoFly_Montana.Droid;
    
    [assembly: ExportRenderer(typeof(Xamarin.Forms.Label), typeof(NeoFly_MontanaLabelRenderer))]
    namespace neoFly_Montana.Droid
    {
        public class NeoFly_MontanaLabelRenderer : Xamarin.Forms.Platform.Android.LabelRenderer
        {
            public NeoFly_MontanaLabelRenderer(Context context) : base(context)
            {
    
            }
        }
    }
    

    0 讨论(0)
提交回复
热议问题