Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom renderer at Xamarin.Forms could find a OnElementChanged method

I'm trying to implement custom label and iOS renderer for it using Xamarin.Forms. For some reason code from sample is using method which is not in a base class:

OnElementChanged

enter image description here

Any ideas how to fix?

like image 557
Alexey Strakh Avatar asked Jun 19 '14 21:06

Alexey Strakh


People also ask

What is the use of custom renderer in Xamarin forms?

Introduction to custom renderers Custom renderers provide a powerful approach for customizing the appearance and behavior of Xamarin. Forms controls. They can be used for small styling changes or sophisticated platform-specific layout and behavior customization.

What are custom renderers?

Custom renderers for a given type can be added to one application project to customize the control in one place while allowing the default behavior on other platforms; or different custom renderers can be added to each application project to create a different look and feel on iOS, Android, and the Universal Windows ...

What is Content page in Xamarin forms?

ContentPage. ContentPage is the simplest and most common type of page. Set the Content property to a single View object, which is most often a Layout such as StackLayout , Grid , or ScrollView . API Documentation. C# code for this page / XAML page.


3 Answers

Change the argument type to ElementChangedEventArgs

using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;

namespace XForms.Toolkit.iOS.Controls
{
    public class MyLabelRenderer : LabelRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<Label> e)
        {
            base.OnElementChanged(e);
        }
    }
}
like image 155
SKall Avatar answered Dec 21 '22 11:12

SKall


It turned out that Xamarin.Forms SDK referenced by project template by default is not enough. You have to install additionally NUGET package Xamarin.Forms for your Touch Project:

enter image description here

like image 27
Alexey Strakh Avatar answered Dec 21 '22 11:12

Alexey Strakh


With me, it worked after an update of the Xamarin.Forms Library in the NUGET Package Manager. But you have to use ElementChangedEventArgs<> as Parameter type

like image 38
troYman Avatar answered Dec 21 '22 10:12

troYman