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
Any ideas how to fix?
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.
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 ...
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.
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);
}
}
}
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:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With