欢迎使用 .NET 多平台应用 UI。此版本标志着我们统一 .NET 平台的多年旅程中的新里程碑。现在,您和超过 500 万其他 .NET 开发人员拥有了针对 Android、iOS、macOS 和 Windows 的一流跨平台 UI 堆栈,以补充 .NET 工具链 (SDK) 和基类库 (BCL)。您可以使用 .NET 构建任何内容。
加入我们的 Microsoft Build 2022,我们将为你介绍使用 .NET 和 Visual Studio 为任何设备构建原生应用的所有更新。» 了解更多。
This is just the beginning of our journey to create desktop and mobile application experiences that satisfy. NET developers. For the next phase, the foundation has now been laid for the broader. NET ecosystem, bringing plug-ins, libraries and services from the. NET Framework and legacy project systems to. NET 6 and SDK-style projects. Currently available products include:
The following are some screenshots of links. There are many direct screenshots of links. If you are interested, click on the original text to view:

有关将库迁移到 .NET 6 的帮助,请查看最近的客座博客文章,其中详细介绍了从 Michael Rumpler (MR.Gestures)和Luis Matos(Plugin.ValidationRules)。
在 18 个月的当前发布计划下,.NET MAUI 工作负载完全受支持,并将以与 .NET 相同的月度数提供服务。我们对 .NET MAUI 的持续关注点仍然是质量,根据您的反馈解决已知问题并确定问题的优先级。这还包括我们提供的工作负载,用于构建专门针对 Android,Android Wear,CarPlay,iOS,macOS 和 tvOS 的应用程序,直接使用.NET 的原生工具包,以及支持库 AndroidX,Facebook,Firebase,Google Play Services 和 SkiaSharp。
With. NET MAUI, you can achieve an uncompromising user experience while sharing more code than ever before. NET MAUI leverages the top application toolkits on each platform, the productivity of modern developers and the use of native UI on our fastest mobile platform to date.
Native UI, uncompromising
.NET MAUI 的主要目标是使您能够提供由每个平台(Android、iOS、macOS 和 Windows)专门设计的最佳应用体验,同时使您能够通过丰富的样式和图形打造一致的品牌体验。开箱即用,每个平台的外观和行为都符合其应有的方式,而无需任何其他小部件或样式来模仿。例如,Windows 上的 .NET MAUI 由 WinUI 3 提供支持,WinUI 3 是 Windows 应用 SDK 附带的首屈一指的原生 UI 组件。

使用 C# 和 XAML 从包含 40 多个控件、布局和页面的丰富工具包生成应用。在移动控件的 Xamarin 肩膀上,.NET MAUI 添加了对多窗口桌面应用程序、菜单栏和新的动画功能、边框、角、阴影、图形等的支持。哦,还有我将在下面重点介绍的新内容:BlazorWebView。

阅读 .NET MAUI 文档中有关控件:页面、布局和视图的详细信息。
Accessibility first
使用原生 UI 的一个主要优点是继承的辅助功能支持,我们可以在语义服务的基础上构建这些支持,以便比以往更轻松地创建高度可访问的应用程序。我们与客户密切合作,重新设计了我们的无障碍开发方式。通过这些对话,我们设计了 .NET MAUI 语义服务来控制:
- Properties such as description, prompt, and title level
- focus
- screen reader
- Automation attributes
阅读 .NET MAUI 文档中有关辅助功能语义服务的详细信息。
Beyond the user interface
.NET MAUI 提供了简单的 API 来访问每个平台的服务和功能,例如加速计、应用操作、文件系统、通知等。在此示例中,我们配置了app actions,用于向每个平台上的应用图标添加菜单选项:
AppActions.SetAsync(
new AppAction("current_info", "Check Current Weather", icon: "current_info"),
new AppAction("add_location", "Add a Location", icon: "add_location")
);

阅读 .NET MAUI 文档中有关访问平台服务和功能的详细信息。
easily customize
无论您是在扩展 .NET MAUI 控件的功能,还是在建立新的平台功能,.NET MAUI 都是针对可扩展性而设计的,因此您绝不会碰壁。以控件为例,控件是在一个平台上以不同方式呈现的控件的规范示例。Android 会在文本字段下方绘制一条下划线,开发人员通常希望删除该下划线。使用 .NET MAUI,只需几行代码即可自定义整个项目中的一切:Entry
#if ANDROID
Microsoft.Maui.Handlers.EntryHandler.Mapper.ModifyMapping("NoUnderline", (h, v) =>
{
h.PlatformView.BackgroundTintList = ColorStateList.ValueOf(Colors.Transparent.ToPlatform());
});
#endif

以下是最近由 Cayas Software 创建新的 Map 平台控件的一个很好的例子。这篇博客文章演示如何为控件创建处理程序,为每个平台实现,然后通过在 .NET MAUI 中注册控件来使其可用。
.ConfigureMauiHandlers(handlers =>
{
handlers.AddHandler(typeof(MapHandlerDemo.Maps.Map),typeof(MapHandler));
})

在 .NET MAUI 文档中阅读有关使用处理程序自定义控件的详细信息
Modern development productivity
As a technology that can build anything, we want. NET to also use common language features, patterns and practices, and tools to increase your productivity.
NET MAUI uses the new C#10 features introduced in. NET 6, including global use of statements and file-wide namespaces, which is ideal for reducing clutter and clutter in files. NET MAUI takes multi-goal positioning to a new level, and we just need to focus on "single projects."

在新的 .NET MAUI 项目中,平台位于一个子文件夹中,将重点放在您花费大部分精力的应用程序上。在项目的“资源”文件夹中,你只需一个位置即可管理应用的字体、图像、应用图标、初始屏幕、原始资源和样式。.NET MAUI 将针对每个平台的独特需求进行优化。

Multiple projects versus single projects still support using separate projects for each platform to build your solution, so you can choose when the single-project approach is appropriate for your application.
.NET MAUI 在 ASP.NET 和 Blazor 应用程序中使用Microsoft.Extensions库中流行的建造者模式作为初始化和配置应用的统一方式。在这里,您可以向 .NET MAUI 提供字体、利用特定于平台的生命周期事件、配置依赖项、启用特定功能、启用供应商控制工具包等。
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.ConfigureServices()
.ConfigureFonts(fonts =>
{
fonts.AddFont("Segoe-Ui-Bold.ttf", "SegoeUiBold");
fonts.AddFont("Segoe-Ui-Regular.ttf", "SegoeUiRegular");
fonts.AddFont("Segoe-Ui-Semibold.ttf", "SegoeUiSemibold");
fonts.AddFont("Segoe-Ui-Semilight.ttf", "SegoeUiSemilight");
});
return builder.Build();
}
}
public static class ServicesExtensions
{
public static MauiAppBuilder ConfigureServices(this MauiAppBuilder builder)
{
builder.Services.AddMauiBlazorWebView();
builder.Services.AddSingleton<SubscriptionsService>();
builder.Services.AddSingleton<ShowsService>();
builder.Services.AddSingleton<ListenLaterService>();
#if WINDOWS
builder.Services.TryAddSingleton<SharedMauiLib.INativeAudioService, SharedMauiLib.Platforms.Windows.NativeAudioService>();
#elif ANDROID
builder.Services.TryAddSingleton<SharedMauiLib.INativeAudioService, SharedMauiLib.Platforms.Android.NativeAudioService>();
#elif MACCATALYST
builder.Services.TryAddSingleton<SharedMauiLib.INativeAudioService, SharedMauiLib.Platforms.MacCatalyst.NativeAudioService>();
builder.Services.TryAddSingleton< Platforms.MacCatalyst.ConnectivityService>();
#elif IOS
builder.Services.TryAddSingleton<SharedMauiLib.INativeAudioService, SharedMauiLib.Platforms.iOS.NativeAudioService>();
#endif
builder.Services.TryAddTransient<WifiOptionsService>();
builder.Services.TryAddSingleton<PlayerService>();
builder.Services.AddScoped<ThemeInterop>();
builder.Services.AddScoped<ClipboardInterop>();
builder.Services.AddScoped<ListenTogetherHubClient>(_ =>
new ListenTogetherHubClient(Config.ListenTogetherUrl));
return builder;
}
}
阅读更多有关.NET MAUI 的文档:app startup with MauiProgram和single project。
Bringing Blazor to desktops and mobile devices
.NET MAUI 也非常适合希望通过原生客户端应用程序参与其中的 Web 开发人员。NET MAUI 与 Blazor 集成,因此您可以直接在原生移动和桌面应用程序中重用现有的 Blazor Web UI 组件。借助 .NET MAUI 和 Blazor,您可以重用 Web 开发技能来构建跨平台原生客户端应用程序,并构建 UI 一致的跨移动、桌面和 Web 的应用。

NET MAUI executes the Blazor component natively on the device (without WebAssembly) and renders it to the embedded Web view control. Because Blazor components are compiled and executed in a. NET process, they are not limited to the Web platform and can also leverage any native platform features such as notifications, Bluetooth, geolocation and sensors, file systems, and more. You can even add native UI controls next to the Blazor Web UI. This is a new hybrid app: Blazor Hybrid!
Getting started with. NET MAUI and Blazor is easy: just use the included. NET MAUI Blazor App project template.

此模板已全部设置,因此您可以使用 HTML、CSS 和 C# 开始构建 .NET MAUI Blazor 应用。适用于 .NET MAUI 的 Blazor 混合教程将引导您完成构建和运行第一个 .NET MAUI Blazor 应用的过程。
或者,将 BlazorWebView 控件添加到现有的 .NET MAUI 应用中,无论你想要在何处开始使用 Blazor 组件:
<BlazorWebView HostPage="wwwroot/index.html">
<BlazorWebView.RootComponents>
<RootComponent Selector="#app" ComponentType="{x:Type my:Counter}" />
</BlazorWebView.RootComponents>
</BlazorWebView>
Blazor 混合支持现在还可用于 WPF 和 Windows 窗体,因此您可以开始对现有桌面应用进行现代化改造,以便在 Web 上运行或使用 .NET MAUI 跨平台运行。WPF 和 Winfrom 的BlazorWebView控件在 NuGet 上可用。查看适用于 WPF 和 Winform 的 Blazor 混合教程,了解如何开始使用。
若要了解有关 Blazor Hybrid 对 .NET MAUI、WPF 和 Windows 窗体的支持的更多信息,请查看 Blazor Hybrid 文档。
Optimized for speed
NET MAUI is designed to improve performance. You have told us how important it is to launch your application as soon as possible, especially on Android. The UI controls in NET MAUI implement a streamlined decoupling handler mapper pattern on native platform controls. This reduces the number of layers in UI rendering and simplifies control customization.
.NET MAUI 中的布局已设计为使用一致的管理器模式,该模式可优化度量值并排列循环,以便更快地呈现和更新 UI。除了 StackLayout 之外,我们还展示了针对特定场景进行预优化的布局,例如 HorizontalStackLayout 和 VerticalStackLayout。
从此旅程的一开始,我们就设定了一个目标,即在过渡到 .NET 6 时提高启动性能并保持或减小应用大小。在正式发布时,我们的 .NET MAUI 提高了 34.9%,Android 版 .NET 提高了 39.4%。这些收益也延伸到复杂的应用程序;.NET Podcast 示例应用程序开始时启动速度为 1299 毫秒,GA 的运行速度为 814.2 毫秒,自预览版 13 以来提高了 37.3%。
These settings are enabled by default to provide these optimizations for the release.

Stay tuned for an in-depth blog post about the work we have done to achieve these results.
starting today
若要开始在 Windows 上使用 .NET MAUI,请安装 Visual Studio 2022 Preview 或更新到版本 17.3 Preview 1.1。在安装程序中,选择工作负载“.NET 多平台应用 UI 开发”。

若要在 Mac 上使用 .NET MAUI,请安装新的 Visual Studio 2022 Preview for Mac (17.3 Preview 1)。
Visual Studio 2022 will release support for. NET MAUI tools later this year. On today's Windows, you can use XAML and. NET Hot Reload, as well as powerful editors for XAML, C#, Razor, and CSS to speed up the development cycle. Using XAML real-time preview and real-time visualization trees, you can preview, align, check, and edit the UI while debugging. NET MAUI's new single-project experience now includes project property pages to provide a visual editing experience to locate and configure applications using multiple platforms.
On Mac, you can now load single and multi-project. NET MAUI solutions to debug with the beautiful, new native Visual Studio 2022 for Mac experience. Additional features to improve the productivity of developing. NET MAUI applications will be available in subsequent previews.
我们建议您立即开始将库更新到 .NET MAUI 并创建新的 .NET MAUI 项目。在深入探讨将 Xamarin 项目转换为 .NET MAUI 之前,请查看依赖项、Visual Studio 对 .NET MAUI 的支持状态以及已发布的已知问题,以确定正确的转换时间。请记住,Xamarin 将继续受现代生命周期策略的支持,该策略声明自上一个主要版本起 2 年。
resources
- .NET MAUI – Workshop
- Building your first .NET MAUI app
- Documentation
- Known Issues
- Microsoft Learn Path
- Q&A Forums
- Release Notes
- Samples
- Support Policy – .NET MAUI
- Support Policy – Xamarin
We need your feedback
我们很乐意听取您的意见!遇到任何问题时,请在 dotnet/maui 的 GitHub 上提交报告。
summary
借助 .NET MAUI,您可以从单个代码库构建适用于 Android、iOS、macOS 和 Windows 的本机应用程序,并使用与在 .NET 中实践的相同的生产力模式。.NET MAUI 的精简且解耦的 UI 和布局体系结构以及单个项目功能使您能够专注于一个应用程序,而不是同时处理多个平台的独特需求。借助 .NET 6,我们不仅为 Android 提供了性能改进,而且还为整个平台目标提供了性能改进。
Less platform code, more shared code, consistent standards and patterns, lightweight and high-performance architecture, mobile and desktop-native experiences-this is just the beginning. We look forward to seeing libraries and the broader ecosystem work with. NET MAUI in the coming months to define a new era of cross-platform application development for. NET developers, allowing you and your organization to achieve more goals.
Reprinted from Blog Park
Original author: www.cnblogs.com/springhgui/p/16304492.html
Original link: gui.h
翻译原文地址:https://devblogs.microsoft.com/dotnet/introducing-dotnet-maui-one-codebase-many-platforms/