From the course: .NET UI Big Picture: Desktop, ASP.NET and Cross-Platform

.NET MAUI: Modern cross-platform UI

- .NET MAUI makes it possible to build native client apps for Windows, macOS, iOS, and Android. Microsoft's naming scheme can be hit or miss, but this time they nailed it with a memorable and fitting acronym. .NET MAUI is designed for developers who want to build specific types of apps. It's ideal for programmers looking to create cross-platform applications using .NET libraries. Those who prefer writing UI layouts in XAML, and developers who favor C# as their primary programming language. Currently, Maui does not support Visual Basic or F#. Use .NET MAUI when you want to share UI layout and design across multiple platforms. It enables us to create a single unified design using XAML and apply it to all targeted platforms, reducing duplication and streamlining development. It's also ideal when you want to share code, tests, and business logic across platforms. This is one of the major benefits of choosing a cross-platform framework. In Visual Studio, your .NET MAUI app is contained within a single project simplifying development. This is a major improvement over the XAML forms approach, where each target platform required a separate project. While that method worked, it often proved frustrating as it led to resource duplication, such as maintaining the same images or assets across multiple platform specific projects. .NET MAUI eliminates this redundancy. In a .NET MAUI app, your code primarily interacts with the T.NET MAUI API. This Unified API provides the tools and abstractions needed to build cross-platform apps, allowing us to focus on app functionality and design rather than platform specific implementation details. Starting with .NET 6, Microsoft provides platform specific frameworks for app development including .NET for Android, .NET for iOS, .NET for macOS, and the WIN UI three library for Windows. Our code interacts with the Maui API, which serves as a bridge to directly consume native platform APIs. Maui apps are bootstrapped through a startup system similar to the one used in. In this context, bootstrap refers to the process of initializing and setting up the elements of a .NET MAUI app when it starts. This enables apps to be initialized from a single location and provides the ability to configure fonts, services, and third party libraries. Plus, it provides a standard way to use dependency injection in the project. .NET MAUI offers a comprehensive collection of controls that developers can use to build rich and interactive user interfaces. These controls serve various purposes, including displaying data. Controls like label, image, and web view allow us to present information and media effectively. Initiating actions. Buttons, sliders, and switches enable users to interact with the app and trigger specific functionality. We can use the controls to indicate activity. Controls such as the activity indicator and progress bar provide visual feedback to inform users about ongoing processes. We can display collections with list and grid controls like, list view and collection view, making it easy to present and manage collections of data. And then finally, we have picking data. Controls like the date picker, time, help users select values intuitively. We don't need to worry about how these controls are implemented on each platform. .NET MAUI takes care of this for us by using platform specific renderers or native controls behind the scenes. This means that when we use a .NET MAUI control, it automatically adapts to and leverages the native UI components on the target platform, ensuring a consistent and native look and feel across platforms. .NET MAUI includes built in cross-platform graphics functionality, providing a versatile drawing canvas for creating custom graphics. This canvas supports drawing and painting shapes, lines, and images, allowing us to create visually rich content. Additionally, it includes common graphic features such as compositing operations, which control how visuals overlap, and graphical transforms for scaling, rotating, and translating graphics. On the hardware side,.NET MAUI provides access to cross-platform APIs for interacting with native device features. These APIs allow us to easily access functionalities like battery status, GPS location, accelerometer data, and network status among others. By abstracting these features into a unified API, this enables us to integrate hardware dependent functionality into our apps without writing platform specific code. .NET MAUI also offers several features to streamline app development. It provides a robust layout engine for designing responsive and visually appealing pages that adapt seamlessly across different devices and screen sizes. We can also use various page types such as content page, tabbed page, and flyout page to create rich and flexible navigation experiences, including drawers, tabs, and split views. Built-in data binding capabilities enable more elegant and maintainable UI development patterns by connecting UI elements directly to data models. Developers who use data binding in XAML based frameworks often follow the Model-View-View-Model, or MVVM design pattern, which .NET MAUI fully supports. MVVM helps create clear separation of concerns between the user interface and the underlying logic making applications easier to maintain and scale. In addition, Microsoft is exploring support for the Model-View-Update or MVU Pattern. MVU is widely used in other frameworks such as Flutter with Dart, SwiftUI for iOS, and React Native. It offers a declarative approach to UI development where the UI is consistently updated in response to state changes. MVU is a simple and straightforward architecture that originated in the context of immutable languages like ELM and F#. But, it has gained popularity across a variety of programming languages. The core idea is to maintain a model that represents the state of the view, ensuring that all updates to the model are handled through a dedicated update function. Here's how it works. Model as the source of truth. The model contains the complete state of the view. With view rendering, the model is passed to the view which renders the UI based on the model's current state. And then, we have user interaction and updates. When the user interacts with the view such as typing into a text box, the view invokes the model's update function. This function takes the user action and produces a new model with the updated state. To summarize what we've seen, .NET MAUI allows us to create multi-platform apps using a single project while still enabling the addition of platform specific source code and resources when necessary. One of the key goals of Maui is to let developers implement as much of their app logic and UI layout as possible in a unified code base. It leverages the best parts of Microsoft's other UI frameworks from UWP to ASP.NET, ensuring a modern, flexible, and familiar development environment. This integration empowers developers to build high-quality apps efficiently with less complexity and more consistency across platforms.

Contents