Xamarin.Forms Custom Renderers: The Escape Hatch That's Closing
Custom Renderers let Xamarin.Forms apps reach native platform APIs without abandoning shared C# logic. But each renderer adds GC pressure, breaks compile-time safety, and won't survive the move to .NET MAUI. A worked BorderlessEntry example shows the pattern — and the costs.
11 Oct 2025, 12:21 UTC

The Problem: Shared Code, Native Expectations
You're building a cross-platform app with Xamarin.Forms. The shared Entry control works fine until design review: iOS needs a done button above the keyboard, Android must lose the underline, and both platforms need custom validation styling that the Forms abstraction doesn't expose. You could write platform-specific pages and abandon code sharing, or you could use the escape hatch Microsoft built for exactly this: Custom Renderers.
The takeaway: Custom Renderers let you keep business logic in .NET Standard while delegating view implementation to UITextField on iOS and RecyclerView on Android. But the pattern adds GC pressure, complicates testing, and — critically — has no future in .NET MAUI. If you're starting fresh, don't use them. If you're maintaining a Xamarin app, understand the costs before you add another renderer.
How the Pattern Works
Every Xamarin.Forms control (Entry, ListView, Map) has a corresponding renderer class (EntryRenderer, ListViewRenderer) that wraps the native counterpart. The renderer lifecycle gives you three precise hooks:
- OnElementChanged — fires when the Forms element is assigned or swapped; the place to wire native events or set one-time properties.
- OnElementPropertyChanged — fires when a bindable property changes on the Forms side; use it to push updates like
TextorIsEnabledto the native view. - Dispose — clean up event subscriptions and native references to avoid leaks.
Registration happens via assembly-level ExportRenderer attributes (or IRendererFactory in 4.7+), letting you replace the default renderer globally or per-page through ControlTemplate. The attribute approach doesn't support generic type parameters — rendering GenericEntry<T> requires a non-generic subclass or a custom factory.
Worked Example: BorderlessEntry
A common ask: remove the native chrome from Entry while keeping Placeholder, Text, Keyboard, and binding intact. Here's the minimal implementation.
Shared Project
public class BorderlessEntry : Entry { }
iOS Project
[assembly: ExportRenderer(typeof(BorderlessEntry), typeof(BorderlessEntryRenderer))]
namespace MyApp.iOS {
public class BorderlessEntryRenderer : EntryRenderer {
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e) {
base.OnElementChanged(e);
if (Control != null) {
Control.BorderStyle = UITextBorderStyle.None;
}
}
}
}
Android Project
[assembly: ExportRenderer(typeof(BorderlessEntry), typeof(BorderlessEntryRenderer))]
namespace MyApp.Droid {
public class BorderlessEntryRenderer : EntryRenderer {
public BorderlessEntryRenderer(Context context) : base(context) { }
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e) {
base.OnElementChanged(e);
if (Control != null) {
Control.Background = null; // removes underline
}
}
}
}
No shared code changes. The Forms BorderlessEntry still participates in layout, validation, and MVVM bindings. The native UITextField and EditText simply lose their default borders.
Trade-offs You'll Feel in Production
Memory and Layout Thrashing
Each renderer instance holds references to both the Forms element and the native view. A page with 50+ custom-rendered controls creates 50+ additional managed objects plus native peers. Profiling with dotnet-trace or Xcode Instruments typically shows Gen 2 collections correlating with renderer instantiation during navigation. If OnElementPropertyChanged triggers frequent native layout passes (common when binding WidthRequest or HeightRequest), you'll see jank on mid-tier Android devices.
Testing Blind Spots
Xamarin.UITest and Appium see only the native view hierarchy. Automation IDs must be duplicated: once on the Forms element (AutomationId) and again on the native control inside the renderer (Control.AccessibilityIdentifier on iOS, Control.ContentDescription on Android). Miss one and your CI pipeline passes while the screen reader or test script fails.
Compile-Time Safety Lost
Accessing the native control requires casting: (UITextField)Control or (EditText)Control. A platform API change (e.g., UITextField dropping a property in iOS 17) becomes a runtime crash, not a build error. Binding library version conflicts with newer Xamarin.GooglePlayServices packages can also break previously working renderers.
The Migration Deadline Is Real
Xamarin.Forms reached end of support on 1 May 2024. No security patches, no iOS 17+ or Android 14+ updates. The replacement, .NET MAUI, replaces Custom Renderers with Handlers (IElementHandler, PropertyMapper, CommandMapper). Handlers decouple property mapping from view construction and support hot reload — but existing renderers do not run under MAUI. You must rewrite each one.
A rough equivalence: the BorderlessEntryRenderer becomes an IEntryHandler where you map BorderStyle and Background in the PropertyMapper instead of overriding lifecycle methods. The mental model shifts from "override and mutate" to "declare how properties translate."
What to Do Today
- Audit your renderers. List every
ExportRendererin the solution. Flag any that touch platform APIs likely to change (keyboard accessories, custom animators, map overlays). - Prototype one Handler. Create a throwaway MAUI project, implement
IEntryHandlerforBorderlessEntry, and measure the effort. Multiply by your renderer count. - Freeze new renderers. For new platform-specific needs, prefer
PlatformConfigurationextensions or Effects (which also migrate to MAUI more cleanly) over new Custom Renderers. - Plan the cutover. If the app ships past 2025, budget a MAUI migration sprint. The renderer rewrite is mechanical but tedious; automate the boilerplate with a Roslyn analyzer if the count exceeds 20.
Custom Renderers were a pragmatic escape hatch. The hatch is closing. Use the remaining time to decide which native behaviors are worth porting and which can be redesigned in shared code.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.