We delivered it in.NET 6 Tie Preview V3. The latest developments in mobile and desktop development for ASP.NET multi-platform application UIs. This version adds the Windows platform and WinUI 3, improves the base application and startup builder, adds native lifecycle events, and adds more UI controls and layouts. We’ve also introduced some new semantic attributes for assistive functionality. As we explore these in more detail, we invite you to join us in creating new applications using dotnet new and to share your feedback.
Support Windows Desktop
Project Reunion 0.5 has been released! Now Windows joins Android, iOS, and MacOS as you can use it. NET Maui reaches the target platform! You can start with the installation instructions for Project Reunion. In this release, we’ve created a sample project that you can explore starting with Visual Studio 2019 16.10 Preview.
Once there is a need for Project Reunion. NET 6 infrastructure, we will add Windows to our single project template.
An introduction to
Since we are still in the early stages of preview, the process of installing all the dependencies needed for mobile and desktop development is still manual. To help you and ourselves, Jonathan Dick has put together a useful tool, the Dotnet Tool, that evaluates your system and collects as many components as possible that you need. To use this tool, you need to install the Maui-Check dotnet tool install -gredth.net.maui.check globally from the command line
Source: https://github.com/Redth/dotn…
Now run > maui-check and follow the instructions. Once successful, you are ready to create your first application: dotnet New Maui-n Hellomaui
Step-by-step instructions on installation and introduction, can also refer to: https://github.com/dotnet/maui/wiki/Getting-Started.
Your first application
.NET Maui uses Microsoft.Extensions HostBuilder to start each application. This provides a consistent pattern for application developers and library maintainers to develop applications quickly. Each platform has a different starting point, but your application entry is uniformly located at startup.cs. Here’s a simple example:
public class Startup : IStartup { public void Configure(IAppHostBuilder appBuilder) { appBuilder .UseMauiApp(); }}
From here, you can perform operations such as registering fonts and registering the Xamarin.forms renderer or custom renderer compatibility. This is where you introduce your App, which implements the Application and is (at least) responsible for creating a new Window:
public partial class App : Application { public override IWindow CreateWindow(IActivationState activationState) { return new MainWindow(); }}
To render your content, a view is added to MainWindow:
public class MainWindow : IWindow { public MainWindow() { Page = new MainPage(); } public IPage Page { get; set; } public IMauiContext MauiContext { get; set; }}
That’s it! You now have a window with content.
Native life cycle events
Preview 3 further improves the startup extension by introducing ConfigureRelifecycleEvents to make it easy to connect to native platform lifecycle events. This is an important introduction, especially for a single-project experience, which simplifies the initialization and configuration required for many libraries.
Here’s a simple example to associate an application with the Android Back button event and handle it as needed:
public class Startup : IStartup
{
public void Configure(IAppHostBuilder appBuilder)
{
appBuilder
.UseMauiApp()
.ConfigureLifecycleEvents(lifecycle => {
#if ANDROID
lifecycle.AddAndroid(d => {
d.OnBackPressed(activity => {
System.Diagnostics.Debug.WriteLine("Back button pressed!");
});
});
#endif
});
}
}
Now let’s take a look at how other libraries can use these methods to simplify their platform initialization. Essentials (Microsoft. Maui. Essentials) library is. Part of.NET Maui, which provides cross-platform non-UI services, we can use this library to configure everything needed for all platforms in a unified location:
public class Startup : IStartup { public void Configure(IAppHostBuilder appBuilder) { appBuilder .UseMauiApp() .ConfigureEssentials(essentials => { essentials .UseVersionTracking() .UseMapServiceToken("YOUR-KEY-HERE"); }); }}
In the Essentials code, you can see how the ConconfigureEssentials extension method is created and linked to platform lifecycle events, greatly simplifying native configuration across platforms.
public static IAppHostBuilder ConfigureEssentials(this IAppHostBuilder builder, Action configureDelegate = null) { builder.ConfigureLifecycleEvents(life => { #if __ANDROID__ Platform.Init(MauiApplication.Current); life.AddAndroid(android => android .OnRequestPermissionsResult((activity, requestCode, permissions, grantResults) => { Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults); }) .OnNewIntent((activity, intent) => { Platform.OnNewIntent(intent); }) .OnResume((activity) => { Platform.OnResume(); })); #elif __IOS__ life.AddiOS(ios => ios .ContinueUserActivity((application, userActivity, completionHandler) => { return Platform.ContinueUserActivity(application, userActivity, completionHandler); }) .OpenUrl((application, url, options) => { return Platform.OpenUrl(application, url, options); }) .PerformActionForShortcutItem((application, shortcutItem, completionHandler) => { Platform.PerformActionForShortcutItem(application, shortcutItem, completionHandler); })); #elif WINDOWS life.AddWindows(windows => windows .OnLaunched((application, args) => { Platform.OnLaunched(args); })); #endif }); if (configureDelegate ! = null) builder.ConfigureServices(configureDelegate); return builder; }
You can see the full class in dotnet/maui. We expect to see more libraries take advantage of this pattern to simplify the way they are used.
Control and layout updates
In addition to the existing compatible Renderers introduced from Xamarin.Forms, we will continue to use the NET Maui adds more controls, properties, and layouts. If you use the above code as the initiator, you will only be able to use handlers that are currently implemented. To see what is currently implemented, look at the Handlers folder at Dotnet/Maui.
To keep track of what we’re doing next, we’ve provided a Project Board for all the handlers that we’ve received the Pull request.
The layout also received some updates in Preview 3. The Grid now supports both absolute size and automatic size (the same as content size). LayoutAlignment options now also can be used in the Grid and the StackLayout, so you can start using HorizontalLayoutAlignment and VerticalLayoutAlignment attributes to locate the view.
Semantic attributes of assistive functionality
We have been working with many customers to better understand the common difficulties encountered in achieving accessibility across multiple native platforms, and how to make it more accessible. NET Maui becomes much easier. One of the steps taken to do this is to add new semantic attributes to map cross-platform attributes to native accessibility attributes.
<Label Text="Welcome to .NET MAUI!" SemanticProperties.HeadingLevel="Level1" FontSize="32" HorizontalOptions="CenterAndExpand" /> <Label Style = "{DynamicResource Glyph}" Text = " SemanticProperties." Description = "Heart" / > < Label Text = "Click the button. You know you want to!" FontSize="18" x:Name="CounterLabel" HorizontalOptions="CenterAndExpand" /> <Button Text="Click Me!" Clicked="OnButtonClicked" SemanticProperties.Hint="Counts the number of times you click"/>
For more information, see the original note and discussion of this dotnet/ Maui issue.
Share your feedback
We’re excited about this release and look forward to your feedback. Please join us on dotnet/ Maui and let us know what you think of these improvements.
For.net if you have any question, please welcome in Microsoft Q&A BBS to ask: https://docs.microsoft.com/en-us/answers/products/dotnet