Xamarin.Forms user interfaces are rendered using the native controls of the target platform, allowing Xamarin.Forms applications to retain the appropriate look and feel for each platform. Custom Renderers let developers override this process to customize the appearance and behavior of Xamarin.Forms controls on each platform.
A new guide on creating custom renderers has recently been published. The guide describes the motivation for custom renderers, the base classes and native controls used for renderers, and custom renderers for specific controls.
Over time the guide will be expanded to cover additional custom renderers.
Exploring the guide
The guide includes the following topics:
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. This article provides an introduction to custom renderers, and outlines the process for creating a custom renderer.
Renderer Base Classes and Native Controls
Every Xamarin.Forms control has an accompanying renderer for each platform that creates an instance of a native control. This article lists the renderer and native control classes that implement each Xamarin.Forms page, layout, view, and cell.
-
The Xamarin.Forms
Entrycontrol allows a single line of text to be edited. This article demonstrates how to create a custom renderer for theEntrycontrol, enabling developers to override the default native rendering with their own platform-specific customization. -
A
ContentPageis a visual element that displays a single view and occupies most of the screen. This article demonstrates how to create a custom renderer for theContentPagepage, enabling developers to override the default native rendering with their own platform-specific customization. -
A Xamarin.Forms
ListViewis a view that displays a collection of data as a vertical list. This article demonstrates how to create a custom renderer that encapsulates platform-specific list controls and native cell layouts, allowing more control over native list control performance. -
A Xamarin.Forms
ViewCellis a cell that can be added to aListVieworTableView, which contains a developer-defined view. This article demonstrates how to create a custom renderer for aViewCellthat's hosted inside a Xamarin.FormsListViewcontrol. This stops the Xamarin.Forms layout calculations from being repeatedly called duringListViewscrolling.
Exploring the samples
Along with the guide there are also sample apps that demonstrate the concepts explained in the guide:
-
This sample demonstrates a custom renderer for the
Entrycontrol, enabling developers to override the default native rendering with their own platform-specific customization. -
This sample demonstrates a custom renderer for a
ContentPage, enabling developers to override the default native rendering with their own platform-specific customization. -
This sample demonstrates a custom renderer that encapsulates platform-specific list controls and native cell layouts.
ViewCell Custom Renderer
This sample demonstrates a custom renderer for aViewCellthat's hosted inside a Xamarin.FormsListViewcontrol, enabling developers to override the default native rendering with their own platform-specific customization.