0

What is the best approach to convert to .net maui?

Current xamarin native app contains of hundreds of pages (developed over 5 years) 2/3 in native and 1/3 made recently in forms, embedded in the native app.

  • Should everything be converted to forms first?

  • Is it possible to embed native pages in a maui project?

  • Attempt to use the maui upgrade assistant?

  • Make a new maui project from scratch?

Thanks

fraldev
  • 43
  • 1
  • 6

2 Answers2

1

You may want to consider converting the Xamarin.Android to .Net7 first which is relatively straightforward. Once working as a .Net7 app, then consider converting it to Maui. Probably by the time you have it as a .Net7 app, .Net8 will be available. That buys you time while Maui is stabilizing

user2153142
  • 431
  • 1
  • 4
  • 7
  • Excellent point. Note: this requires rewriting any Xamarin.Forms UI into Android UI (question mentions some XF). – ToolmakerSteve Jun 23 '23 at 18:46
  • Another helpful procedure before converting to Maui would be to set #nullable enable in all the files in the existing project (I'd suggest one at a time to keep your sanity) as nullable is enabled by default for .Net7 and above. If it is a big project as you have suggested you may as well get it cleaned up before you attempt any conversion. If you have never used nullable, you are in for tedious, repetitious work. A good example of where Copilot can be very helpful. – user2153142 Jun 26 '23 at 07:31
1

Should everything be converted to forms first?

No. Definitely Not. Make a new Maui project. In that, you'll see folder Platforms, which contains subfolders Android, etc. That's where platform-specific code goes.

Is it possible to embed native pages in a maui project?

Yes, by writing a custom handler. See SO answer - Native view via custom handler. See also Create a custom control using handlers.

Writing custom handlers is more work than the Xamarin.Forms approach to embedding native controls, but the result is higher-performance rendering of the Maui+native page layout.

Attempt to use the maui upgrade assistant?

Yes. To see the changes it makes. TBD whether you then use that as starting point, or make a new project, as I mention in answer to first bullet point. If make a new project, you'll be copying your converted files into appropriate places, depending on whether cross-platform, or platform specific. You'll also examine the .csproj(s) made by upgrade assistant. You'll need to copy portions of that to the "new maui .csproj.

Make a new maui project from scratch?

Probably ideal in the long-term. OTOH, you have to know what you are doing, as that will involve moving code around, and moving sections of .csproj(s). See my responses above.

May be best to use upgrade assistant version first. See if you can get that to do what you need.
HOWEVER, you may sometimes encounter tutorials/example-code that won't work as-is with your upgraded solution.

BOTTOM LINE: Attempt BOTH WAYS: upgrade assistant version, AND start-from-scratch version, adding source files gradually (not all at once). You'll learn a lot by comparing how those work.

ToolmakerSteve
  • 18,547
  • 14
  • 94
  • 196
  • Thanks for the answer. I can't see any information about embedding native pages in a maui app from the link you have added. Only how to embed Maui controls in a native app. Maybe its me thats blind? – fraldev Jun 23 '23 at 08:01
  • You are right. I assumed there was a built-in way that handled any native view. Instead, you have to write a custom handler for each type of view. I think this is a consequence of the tighter coupling between Maui renderers and native control renderers. I've fixed that part of answer. The custom renderer doc doesn't give as much detail as needed; search for github custom control repos for examples. [Ali's Maui.FreakyControls](https://github.com/FreakyAli/Maui.FreakyControls) is a good starting point. Those controls are not native, but they are good examples of making custom handlers. – ToolmakerSteve Jun 23 '23 at 18:29