docs-maui
docs-maui copied to clipboard
Documentation not sufficient for any Xamarin.Forms CustomRenderer Migration in .NET MAUI
The described code in "Reuse custom renderers in .NET MAUI" is only valid for the referenced example, but not for any custom renderer.
I tried to migrate an Entry CustomRenderer and got an InvalidCastException
with the code provided from the docs in the MauiProgram.cs
Workaround: When I add.UseMauiCompatibility() to the MauiAppBuilder and call the .AddCompatibilityRenderer like:
var builder = MauiApp.CreateBuilder();
builder
.UseMauiCompatibility()
.UseMauiCommunityToolkit()
.UseMauiApp(serviceProvider => new App(serviceProvider))
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
})
.ConfigureMauiHandlers((mauiHandlerCollection) =>
{
#if ANDROID
mauiHandlerCollection.AddCompatibilityRenderer(
typeof(MyEntry),
typeof(TaskyApp.Droid.CustomRenderer.MyEntryRenderer));
#elif IOS
mauiHandlerCollection.AddCompatibilityRenderer(
typeof(MyEntry),
typeof(TaskyApp.iOS.CustomRenderer.MyEntryRenderer));
#endif
});
it works.
Code example is provided here.
It would be good when the docs get updated to capture any custom renderer reuse.
Document Details
⚠ Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.
- ID: c787fde2-1c9c-62d4-2cdd-93681e0c1ff5
- Version Independent ID: c787fde2-1c9c-62d4-2cdd-93681e0c1ff5
- Content: Reuse custom renderers in .NET MAUI - .NET MAUI
- Content Source: docs/migration/custom-renderers.md
- Product: dotnet-mobile
- Technology: dotnet-maui
- GitHub Login: @davidbritch
- Microsoft Alias: dabritch