Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
vermeir_nico_introducing_net_6_getting_started_with_blazor_m.pdf
Скачиваний:
19
Добавлен:
26.06.2023
Размер:
11.64 Mб
Скачать

Chapter 5 Blazor

Since this is basically a control running on a form, we are free to mix Blazor components with WinForms controls to create fully hybrid applications.

Wrapping Up

As we have seen, Blazor is Microsoft’s answer to popular client-side frameworks like Angular and React. It allows us to build powerful, dynamic, and beautiful web applications using .NET instead of JavaScript. Blazor comes in different flavors, fully client-side, thanks to the power of WebAssembly of client-server, thanks to real-time communication over SignalR.

Besides being a framework for building web applications, Microsoft has been investigating bringing it to different platforms. The result of that can be found in the Prerelease version of the BlazorWebView. With the BlazorWebView, we can share Blazor components from the web to WPF and WinForms and eventually even to mobile applications with MAUI.

152

CHAPTER 6

MAUI

MAUI, or the Multi-Application User Interface, is the next iteration of Microsoft’s Xamarin framework. Xamarin has come a long way since its startup days back in 2011. It has evolved from being a C# wrapper around Java and Objective-C to a world-­ class cross-platform library, enabling mobile developers to write apps for multiple platforms in the same language, without ever having to switch back to the platform’s native language. All of this was, thanks to Mono, an open-source implementation of

.NET. Mono’s original reason of existence was bringing .NET to the Linux world, enabling Mono developers to build Linux-based desktop applications with C# and Visual Basic. Mono quickly evolved to a platform that brings .NET to a wide range of architectures and operating systems, even into the world of embedded systems. Since Android and iOS are *Nix-based operating systems, it wasn’t that far-fetched to get a version of Mono running on these mobile platforms, and thus Xamarin was born.

In 2014 Xamarin released Xamarin.Forms, which adds an extra UI abstraction layer on top of Xamarin. It further abstracts platform differences by enabling developers to write a UI once and run it on different platforms.

Microsoft acquired Xamarin in 2016; they made the framework license free and even gave it a more open open-source license. The Xamarin community has grown large since then. Since the acquisition focus has shifted from more Xamarin Native to Xamarin Forms, pushing XAML as the UI framework of choice. A lot of work was done to improve performance and stability. The tooling greatly increased, bringing us a UI Previewer and telemetry tools.

With MAUI, a new chapter in the life of Xamarin begins. MAUI will aim to shorten the developer loop (develop–build–run) and greatly improve the tooling. MAUI can target Android, iOS, Windows, and MacOS.

153

© Nico Vermeir 2022

N. Vermeir, Introducing .NET 6, https://doi.org/10.1007/978-1-4842-7319-7_6

Chapter 6 MAUI

Project Structure

The most prominent change is the new project structure. A new Xamarin.Forms solution in Visual Studio already contained three projects before any code was written, as shown in Figure 6-1.

Figure 6-1.  A classic Xamarin Forms project

A newly created Xamarin.Forms app that can run on Android and iOS consists of three projects: a Xamarin.Android project, a Xamarin.iOS project, and a .NET class library. The Android and iOS project are what we call the “platform heads”; they exist mainly to bootstrap the Xamarin.Forms platform and call into the shared code that lives in the .NET class library, XamarinDemo.Shared. The two platform heads are also used whenever an app needs platform-specific implementations; this might be needed if the cross-platform layer doesn’t suffice.

154

Chapter 6 MAUI

Figure 6-2 shows a newly created MAUI application using The Blank MAUI app template in Visual Studio in .NET 6.

Figure 6-2.  A new .NET 6 MAUI project

This app supports Android, iOS, Windows, and Mac Catalyst. You’ll notice that the multiple platform heads are gone; instead, we get one class library that contains a

Platforms folder containing a folder for each platform we’re supporting with our app. This is mostly done through compiler magic; we still get an APK file for Android and an IPA for iOS, but our code is easier to manage since it’s all in one place. Selecting which platform to launch or debug on is built into the new Visual Studio tooling, as shown in Figure 6-3.

Figure 6-3.  Selecting the debug target

155