Issue with CustomScrollViewRenderer in MAUI Migration – ScrollView Content Not Displaying

KarPreet 60 Reputation points
2024-11-12T05:34:58.3633333+00:00

Hello,

I’m currently migrating a Xamarin.Forms application to .NET MAUI, and I’m encountering an issue with a CustomScrollRenderer that was previously working fine in Xamarin.Forms. In the Xamarin project, I used a custom renderer for ScrollViewRenderer, but when I add it to my MAUI project, it causes all content within scroll views to appear empty.

Here’s the relevant setup in MauiProgram.cs:

builder

.UseMauiApp<App>()

.ConfigureMauiHandlers(handlers =>

{

#if ANDROID

handlers.AddCompatibilityRenderer(typeof(CustomScrollView), typeof(SKM_MOBILE.Droid.Renderers.CustomScrollRenderer));

#endif

});

And my CustomScrollRenderer class:
namespace SKM_MOBILE.Droid.Renderers

{

public class CustomScrollRenderer : ScrollViewRenderer

{

public CustomScrollRenderer() : base(MainActivity.Instance.ApplicationContext)

{

}

}

}

Problem:

  • When AddCompatibilityRenderer is enabled, all scroll view content is empty.
  • **If I comment out AddCompatibilityRenderer, the scroll view contents render as expected.
    **
    I’m wondering if there are any known issues or additional steps required for compatibility renderers in MAUI, specifically for ScrollViewRenderer. I’d appreciate any guidance or suggestions on resolving this issue.
.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,696 questions
{count} votes

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 45,181 Reputation points Microsoft Vendor
    2024-11-12T08:00:01.1233333+00:00

    Hello,

    The AddCompatibilityRenderer registration method is currently deprecated in Maui. If you need to continue using Renderer in Maui, you should use the AddHandler method to register.

    Please refer to Register renderers for more details.

    In addition, since Renderer has been deprecated in Maui and will not be updated any more. it is recommended that you refer to Migrate a Xamarin.Forms custom renderer to a .NET MAUI handler to migrate it to Handler.

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.