Home Blog Tech Xamarin Forms Custom UI Components. Part 4: Custom Renderers

Xamarin Forms Custom UI Components. Part 4: Custom Renderers

If you are looking at UI components available in Xamarin Forms, you may get the impression, that not everything which is possible natively against iOS/Android and which seems that should be possible also in Xamarin Forms, is available.

Let’s imagine strike through feature at label/textview – it’s something really basic. As you may notice, it’s also available in WordPress ;), but it’s NOT available in Xamarin Forms.

So… How to deal with it? How to implement it?

First of all, we must find a solution for striking through text for:

Next step is to extend default Label class of Xamarin Forms, in our PCL (base) project, in order to define new property called IsStrikeThrough:

With such prepared extended Label – ExtendedLabel – we can implement platform specific code, based on solutions found at StackOverflow, but mapped into C# code.
For Android sub-project:

For iOS sub-project:

and that’s it! We can start using our custom ExtendedLabel:

The final outcome of our customization, in example of Android application:
Label strike through

As you can see, customisation of native UI components isn’t terrible, and in most cases, we can simply find a native solution for our problem and “map” founded code into C# wrap in Xamarin Forms.

Until recently, he was Java EE developer, who have been developing extensive PLM system (Windchill) and integrating it with SAP system. Later, he was using the Spring framework and WSO2, while developing a LIMS class system. Recently, he changed technology and engaged in developing cross-platforms mobile applications, using the Xamarin Forms framework. Sometimes, he has nightmares because of that.Speaking of his hobby, he is interested in a car computer diagnostics. He is also the author of the Polish translation of the built-in navigation system Magneti Marelli RT3, appearing in Peugeot, Citroen, Fiat, Lancia, and Maserati cars.