Search code examples
mauimaui-android

Adding platform view to Maui ContentView during runtime


Im porting a Xamarin app to Maui, and hit a dead end. The app is using a third party library to use Azure Communication Services, and once a connection is established, the Android version returns a class "VideoStreamRendererView" which inherits from android FrameLayout.

In the old Xamarin app I just called the "ToView" extension, and set the "Content" attribute of the ContentView to the resulting View, and everything worked...

The ToView extension is also there in Mauit: Microsoft.Maui.Controls.Compatibility.Platform.Android.LayoutExtensions.ToView, but using this and adding to Content gives me a runtime exception:

Microsoft.Maui.Platform.HandlerNotFoundException: Handler not found for view Microsoft.Maui.Controls.Compatibility.Platform.Android.NativeViewWrapper.

I tried reading through the documentation for Handlers, but cant wrap my head around how to use this with a runtime generated instance of the native view.... Appreciate any tips!


Solution

  • Figured this out myself.

    Basically I needed to make a ViewHandler for this to work, details here: https://github.com/Laerdal/Xamarin.AzureCommunicationCalling/discussions/51