Search code examples
xamarinlayoutcontrolsmaui

Porting Xamarin to Maui - Custom control


I have a custom control CustomView with a couple of bindable properties

namespace App.Maui.Controls
{
   public class CustomView : Layout<Layout>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:controls="using:App.Maui.Controls">
  <controls:CustomView IsOpen="{Binding ViewModel.IsOpen}">

When porting my Xamarin app to Maui, the code compiles fine, but I get the following error when trying to display the control:

Microsoft.Maui.Platform.HandlerNotFoundException: 'Handler not found for view App.Maui.Controls.CustomControl.'

The error seems quite straight-forward but the solution eludes me - following a plethora of guides they never mention handlers, nor does it seem required to have platform specific implementations for a base control.

How do I define a handler for such a basic control?


Solution

  • I had to rewrite the classes to suit Maui's new way it handles custom controls.

    I followed https://github.com/hartez/CustomLayoutExamples as a source.