.NET MAUI in .NET 10 Preview: A Focus on Quality and the Developer Experience

syncfusionsyncfusion
11 min read

TL;DR: Learn how .NET 10 Preview takes .NET MAUI to the next level with performance enhancements, modular NuGet packages, and refined UI controls. This update focuses on boosting developer productivity through simplified Android tooling, improved cross-platform stability, and more intuitive design-time support, making it easier to build sleek, responsive apps across devices.

As .NET developers, we’re always eager to explore the latest advancements in our toolkit. With the arrival of the .NET 10 Preview, the focus for .NET Multi-platform App UI (.NET MAUI) has squarely landed on a crucial aspect: improving product quality. This release isn’t about a massive overhaul of features but rather a refinement and stabilization of the existing framework, alongside some welcome enhancements that promise a smoother development experience.

In this blog, we’ll delve into the specifics of what .NET 10 will bring to the .NET MAUI landscape next November. Drawing directly from the official preview documentation, we’ll explore the key improvements, new functionalities, and important changes you need to be aware of as you continue building cross-platform apps.

Laying the groundwork: Workloads, NuGet packages, and support policies

One of the foundational shifts in .NET MAUI with .NET 10 will be its distribution model. Instead of being a monolithic entity, .NET MAUI will ship as a .NET workload and have a collection of individual NuGet packages.

This might seem like a subtle change, but it offers significant advantages. For instance, it empowers us to pin our projects to specific versions of .NET MAUI, providing greater control and predictability over our app’s dependencies.

Furthermore, this modular approach allows for easier previewing of unreleased or experimental builds, giving us a sneak peek into future innovations and the opportunity to provide valuable feedback.

It’s also crucial to note the distinct .NET MAUI support policy, which differs from the standard .NET and .NET Core policies due to its reliance on external dependencies like Xcode and Android SDK Tools. Stay informed about this policy so you have a clear understanding of the support lifecycle for your .NET MAUI apps.

Enhancing the User Interface: Control improvements

A significant portion of the .NET 10 update focuses on refining the user interface controls we use daily. Let’s explore some of these enhancements.

Small visual details can significantly impact the user experience. In .NET 10, the SearchBar control will introduce a new bindable property called SearchIconColor. As the name suggests, this property will allow you to set the color of the search icon, enabling better visual integration with your app’s theme.

A simple XAML code example demonstrates its usage:

<SearchBar Placeholder="Search items..." SearchIconColor="Blue" />

CollectionView and CarouselView evolve

If you’ve been working with .NET MAUI, you’re likely familiar with the CollectionView and CarouselView. In .NET 9, optional handlers were introduced for these controls on iOS and Mac Catalyst, promising improved performance and stability.

The good news is that these performance-boosting handlers will be the default in .NET 10. This means that by simply targeting .NET 10, your apps leveraging these controls will inherently benefit from these underlying improvements.

Visual feedback for Switches

According to the preview, the Switch control, fundamental for toggling settings, is offering more visual customization. With the introduction of the OffColor bindable property, you will be able to define the color of the switch when it’s in the off state. This complements the existing OnColor property, providing finer-grained control over the visual representation of the switch’s state.

Refer to the following code example.

<Switch OffColor="Red" OnColor="Green" />

HybridWebView gets more flexible

The HybridWebView control, a powerful tool for embedding web content within your native apps, will gain a new capability in .NET 10. A new InvokeJavaScriptAsync overload will be added, which allows you to invoke a specified JavaScript method without needing to specify any information about the return type.

This simplifies the interaction between your .NET MAUI code and the JavaScript running within the WebView when you don’t expect a specific value back.

Farewell to TableView, hello CollectionView

It’s important to note that the TableView control will be deprecated in .NET 10. The recommended alternative for displaying data in a table-like format is the more flexible and better-performing CollectionView.

If you have existing apps using TableView, it’s a good time to start planning your migration to CollectionView to benefit from its modern features and ongoing support.

Internal changes, external solutions: MessagingCenter

A notable architectural change in .NET 10 Preview is that the MessagingCenter class has been made internal. While this might seem like a breaking change, the documentation provides a clear path forward.

The recommended approach is to replace MessagingCenter usage with the WeakReferenceMessenger available in the CommunityToolkit.Mvvm NuGet package. This aligns with modern MVVM practices and often leads to more robust and maintainable code by mitigating potential memory leaks.

Adding depth with shadows

Visual enhancements continue with the ShadowTypeConverter class in the Microsoft.Maui.Controls namespace, which will be public in .NET 10. This change will likely provide more direct access and control over how shadows are specified and applied to UI elements, potentially allowing for more intricate and customized shadow effects using formatted strings.

Deeper platform integration: Expanding native capabilities

The .NET MAUI’s strength lies in its ability to bridge the gap between a single codebase and native platform features. The .NET 10 Preview brings several enhancements that further deepen this integration.

Fine-tuning speech output

The SpeechOptions class, used with the TextToSpeech functionality, gains a new Rate property. This allows you to control the speech rate, providing more flexibility in how text is synthesized and spoken by the device.

Streamlining accessibility on iOS and Mac Catalyst

For developers focusing on accessibility, the .NET 10 Preview introduces changes to how accessibility hints and labels are managed on iOS and Mac Catalyst.

The following AccessibilityExtensions methods in the Microsoft.Maui.Controls.Compatibility.Platform.iOS namespace will be deprecated in .NET 10:

  • SetAccessibilityHint

  • SetAccessibilityLabel

The recommended alternative is to use the Microsoft.Maui.Platform.UpdateSemantics method. This will provide a more unified and consistent approach to setting accessibility information across platforms.

Enhanced control over WebView navigation on iOS and Mac Catalyst

Developers working with WebView controls on iOS and Mac Catalyst will appreciate the new overridable methods in the MauiWebViewNavigationDelegate class within the Microsoft.Maui.Platform namespace:

  • DecidePolicy

  • DidFailNavigation

  • DidFailProvisionalNavigation

  • DidFinishNavigation

Making these methods overridable provides greater control over the navigation lifecycle within the WebView, allowing for more customized behavior in response to navigation events.

Displaying modal pages as popovers on iOS and Mac Catalyst

A particularly interesting platform-specific addition for iOS and Mac Catalyst is the ability to display a modal page as a popover. This offers a more contextual and less intrusive way to present additional information or gather user input. This functionality is consumed by setting the following bindable properties on the page:

  • Page.ModalPopoverSourceView: Defines the view that acts as the source of the popover.

  • Page.ModalPopoverRect: Specifies the rectangle within the source view from which the popover will originate.

  • Page.ModalPresentationStyle: Set to Popover to enable the popover presentation style.

This code example illustrates how this can be implemented.

using Microsoft.Maui.Controls.PlatformConfiguration;
using Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific;

public partial class PopoverPage : ContentPage
{
    public PopoverPage(View modal, Rectangle rectangle)
    {
        InitializeComponent();
          On<iOS>().SetModalPopoverView(modal);
          On<iOS>().SetModalPopoverRect(rectangle);
          On<iOS>().SetModalPresentationStyle(UIModalPresentationStyle.Popover);
    }
}

// ...

Page modalPage = new PopoverPage(originButton, Rectangle.Empty);
await Navigation.PushModalAsync(modalPage);

This new capability will open up possibilities for creating more refined and user-friendly interfaces on iOS and Mac Catalyst.

Modernizing XAML markup: Font icons

In the realm of XAML, .NET 10 will be deprecating the FontImageExtension markup extension. The recommended replacement is the FontImageSource type. This change aligns with a more object-oriented approach to defining font icons within your XAML.

The documentation provides examples of both inline usage and property element syntax.

<!-- Using FontImageSource directly -->
<Button Text="Press me" Background="Transparent" TextColor="{AppThemeBinding Light=Black, Dark=White}"
        ImageSource="{FontImageSource Glyph=MyGlyph, Color={AppThemeBinding Light=Black, Dark=White}, FontFamily=FontAwesome, Size=18}" />

<!-- Using property element syntax -->
<Button Text="Press me" Background="Transparent" TextColor="{AppThemeBinding Light=Black, Dark=White}" >
    <Button.ImageSource>
        <FontImageSource Glyph="MyGlyph" Color="{AppThemeBinding Light=Black, Dark=White}" FontFamily="FontAwesome" Size="18" />
    </Button.ImageSource>
</Button>

While this requires a slight adjustment to existing XAML, it promotes better readability and maintainability.

.NET for Android: Performance, tooling, and API updates

The .NET 10 release will bring a host of improvements specifically targeting Android development within .NET MAUI, according to the Preview. The focus here is on reducing build times, enhancing performance, and embracing the latest Android APIs.

Embracing new Android APIs and JDK

.NET for Android in .NET 10 will add support for API 36 (Android 16 Baklava beta 2) and JDK 21. This ensures that we can leverage the newest platform features and development tools.

To target the Android 16 Preview API, you’ll need to download the Android 16 platform using the SDK Manager and update your project’s target framework to net10.0-android36.

Setting a new minimum: API level 24

The default $(SupportedOSPlatformVersion) in .NET for Android project templates is being updated to 24 (Nougat), moving away from the previous default of 21 (Lollipop).

While API 21 is still supported, this change is recommended to prevent runtime crashes related to desugaring when using Java default interface methods. It’s advisable to update existing projects to API 24 to avoid potential unexpected errors.

Dotnet run comes to Android

A welcome addition for Android developers will be the support for the dotnet run command. Right now, this isn’t feasible because the target Android device or emulator must be specified. In .NET 10, you can use dotnet run with the —p**:AdbTarget** parameter to specify the target.

Refer to the following code example.

// Run on the only attached Android physical device  
dotnet run -p:AdbTarget=-d

// Run on the only running Android emulator  
dotnet run -p:AdbTarget=-e

// Run on the specified Android physical device or emulator  
dotnet run -p:AdbTarget="-s emulator-5554"

This streamlines the development workflow by allowing you to build and deploy your Android app directly from the command line. The $(AdbTarget) property is passed directly to adb for device interaction.

Marshal methods are enabled by default

To improve startup performance, .NET 9 introduced a new way of creating marshal methods for Java-to-C# interop. However, this feature was disabled by default.

In .NET 10, these marshal methods will be enabled by default. While this generally improves startup times, it’s noted that problems with these methods might manifest as hangs during startup. If you encounter such an issue, you can try disabling them by setting the $(AndroidEnableMarshalMethods) MSBuild property to false in your project file. If this resolves the hang, it’s encouraged to file an issue for further investigation.

Customizing Maven Library filenames

The @(AndroidMavenLibrary) item, introduced in .NET 9, allows automatic downloading and binding of Java libraries from Maven. By default, the downloaded library is named based on its artifact ID and version.

The .NET 10 will introduce the ArtifactFilename metadata for this item, allowing you to specify an alternative filename. This can be useful in scenarios where the default naming convention doesn’t align with your project’s requirements.

Faster design-time builds

To accelerate the design-time experience in Visual Studio, the aapt2 tool will no longer be invoked during design-time builds. Instead, .aar files and underlying Android resources will be parsed directly.

This optimization can significantly reduce design-time build durations, as demonstrated by improvements in unit test build times.

Optimizing Java-to-C# Interop

Further performance optimizations have been implemented in the Preview by removing codepaths that might use System.Reflection.Emit from Java calling into C# codepaths.

This aims to improve app startup and overall performance by avoiding potential runtime code generation.

Fixing ApplicationAttribute issue

Finally, .NET 10 will resolve an issue where setting the ApplicationAttribute.ManageSpaceActivity property could result in an InvalidCastException.

.NET for iOS: Trimming, bundling, and platform support

.NET 10 will also bring important updates for development on iOS, tvOS, Mac Catalyst, and macOS. The supported platform versions are:

  • iOS: 18.2

  • tvOS: 18.2

  • Mac Catalyst: 18.2

  • macOS: 15.2

Trimmer warnings are enabled by default

Previously, trimmer warnings in the base class library were suppressed, making it challenging to address all warnings in user code. However, after the resolution of iOS trimmer warnings in .NET 9, trimmer warnings will now be enabled by default in .NET 10.

This encourages the development of more trim-friendly apps, leading to smaller app sizes. If you need to disable trimmer warnings, you can set the $(SuppressTrimAnalysisWarnings) MSBuild property to true in your project file.

Opting out of original resource bundling

In .NET 9, opt-in support was added for embedding original resources (like storyboards, XIBs, and images) in library projects. This was done to facilitate decision-making based on original resources during app building. In .NET 10, this behavior will have an opt-out.

To revert to the previous behavior of processing resources before embedding, you can set the $(BundleOriginalResources) MSBuild property to false in your library project file.

This change acknowledges that resource processing often requires a Mac and Apple’s toolchain, potentially complicating library builds on other platforms.

Conclusion: A step forward in .NET MAUI maturity

Thanks for reading! In this blog, we’ve explored how .NET 10 will represent a significant step in .NET MAUI toward a more stable, high-performing, and developer-friendly cross-platform experience. While it might not introduce a plethora of brand-new features, the focus on improving product quality, refining existing controls, and deepening platform integration will improve the framework’s long-term health and usability.

As .NET developers, these changes will empower us to build more robust and efficient apps. The enhancements in control behavior, the deeper platform integration capabilities, and the performance improvements in .NET for Android and iOS will all contribute to a smoother development workflow and better end-user experiences.

It’s highly recommended to explore the release notes for each preview version of .NET MAUI in .NET 10 to gain a more granular understanding of the specific fixes and changes. By embracing these updates and adapting our development practices accordingly, we can continue to leverage the power of .NET MAUI to create compelling cross-platform apps. Happy coding!

For our existing Syncfusion customers, the newest version of Essential Studio is available from the license and downloads page. If you are not a customer, try our 30-day free trial to check out these new features.

If you have questions, contact us through our support forums, feedback portal, or support portal. We are always happy to assist you!

0
Subscribe to my newsletter

Read articles from syncfusion directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

syncfusion
syncfusion

Syncfusion provides third-party UI components for React, Vue, Angular, JavaScript, Blazor, .NET MAUI, ASP.NET MVC, Core, WinForms, WPF, UWP and Xamarin.