{"id":33359,"date":"2021-06-17T12:17:54","date_gmt":"2021-06-17T19:17:54","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/dotnet\/?p=33359"},"modified":"2021-06-21T14:53:39","modified_gmt":"2021-06-21T21:53:39","slug":"announcing-net-maui-preview-5","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/dotnet\/announcing-net-maui-preview-5\/","title":{"rendered":"Announcing .NET MAUI Preview 5"},"content":{"rendered":"<p>While we are still recovering from Microsoft Build and <a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/announcing-net-maui-preview-4\/\">.NET 6 Preview 4<\/a>, we are here to share our continued progress with .NET Multi-platform App UI (.NET MAUI) with <a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/announcing-net-6-preview-5\/\" rel=\"noopener\" target=\"_blank\">.NET 6 Preview 5<\/a>. In this release we have enabled animations and view transformations, completed the porting of several UI components, and introduced improvements to the single project templates.<\/p>\n<p>We have also published our first batch of preview documentation covering introductory and foundational aspects of .NET MAUI: <a href=\"https:\/\/docs.microsoft.com\/dotnet\/maui\/\">https:\/\/docs.microsoft.com\/dotnet\/maui\/<\/a>.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2021\/06\/mauiFadeTo.gif\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-33367\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2021\/06\/mauiFadeTo.gif\" alt=\"Image mauiFadeTo\" width=\"1024\" height=\"546\" \/><\/a><\/p>\n<h2>Animations<\/h2>\n<p>There are a few ways to perform <a href=\"https:\/\/docs.microsoft.com\/xamarin\/xamarin-forms\/user-interface\/animation\/\">animation<\/a> in .NET MAUI, the easiest of which is using <a href=\"https:\/\/docs.microsoft.com\/xamarin\/xamarin-forms\/user-interface\/animation\/simple\">view extension methods<\/a> such as <code>FadeTo<\/code>, <code>RotateTo<\/code>, <code>ScaleTo<\/code>, <code>TranslateTo<\/code>, and more. In the following example I grab a reference to each view bound to the layout (see <a href=\"https:\/\/docs.microsoft.com\/xamarin\/xamarin-forms\/user-interface\/layouts\/bindable-layouts\">bindable layouts<\/a>) using the new <a href=\"https:\/\/github.com\/dotnet\/maui\/pull\/1200\"><code>HandlerAttached<\/code><\/a> event:<\/p>\n<pre><code class=\"language-xaml\">&lt;DataTemplate x:Key=\"FavouriteTemplate\"&gt;\r\n    &lt;Frame\r\n        AttachedHandler=\"OnAttached\"\r\n        Opacity=\"0\"&gt;\r\n        ...\r\n    &lt;\/Frame&gt;\r\n&lt;\/DataTemplate&gt;<\/code><\/pre>\n<pre><code class=\"language-xaml\">&lt;FlexLayout\r\n    BindableLayout.ItemTemplate=\"{StaticResource FavouriteTemplate}\"\r\n    BindableLayout.ItemsSource=\"{Binding Favorites}\"\r\n    &gt;\r\n    ...\r\n&lt;\/FlexLayout&gt;<\/code><\/pre>\n<p>When the page appears I then animate the views in with a slight stagger to create the beautiful cascade effect.<\/p>\n<pre><code class=\"language-csharp\">public partial class FavoritesPage : ContentPage\r\n{\r\n    List&lt;Frame&gt; tiles = new List&lt;Frame&gt;();\r\n\r\n    void OnAttached(object sender, EventArgs e)\r\n    {\r\n\r\n        Frame f = (Frame)sender;\r\n        tiles.Add(f);\r\n    }\r\n\r\n    protected override async void OnAppearing()\r\n    {\r\n        base.OnAppearing();\r\n\r\n        await Task.Delay(300);\r\n        TransitionIn();\r\n    }\r\n\r\n    async void TransitionIn()\r\n    {\r\n        foreach (var item in tiles)\r\n        {\r\n            item.FadeTo(1, 800);\r\n            await Task.Delay(50);\r\n        }\r\n    }    \r\n}<\/code><\/pre>\n<p>For more complete orchestration of view animations, check out the <a href=\"https:\/\/docs.microsoft.com\/xamarin\/xamarin-forms\/user-interface\/animation\/custom\">Custom Animation documentation<\/a> which demonstrates adding multiple child animations that can run parallel.<\/p>\n<p>You can view and run the source for this example from the <a href=\"https:\/\/github.com\/davidortinau\/WeatherTwentyOne\/\">WeatherTwentyOne project on GitHub<\/a>.<\/p>\n<h2>UI Components<\/h2>\n<p>In this release several controls now have all properties and events ported to handlers from the renderer architecture of Xamarin.Forms, including <code>ActivityIndicator<\/code>, <code>CheckBox<\/code>, <code>Image<\/code>, and <code>Stepper<\/code>. In previous previews you would need to check if a control was ported and register renderers from the compatibility package for those unavailable. In .NET MAUI Preview 5 we have made this much easier by updating the <code>UseMauiApp<\/code> extension (see the <a href=\"https:\/\/github.com\/dotnet\/maui\/wiki\/Application-Startup\">Startup wiki<\/a>) to wire up all the controls for you, whether they are based on handlers or renderers.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2021\/06\/maui-pre5-controls.png\"><img decoding=\"async\" class=\"aligncenter size-large wp-image-33369\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2021\/06\/maui-pre5-controls-1024x814.png\" alt=\"Image maui pre5 controls\" width=\"640\" height=\"509\" srcset=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2021\/06\/maui-pre5-controls-1024x814.png 1024w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2021\/06\/maui-pre5-controls-300x239.png 300w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2021\/06\/maui-pre5-controls-768x611.png 768w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2021\/06\/maui-pre5-controls.png 1294w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<p>Also new in preview 5 is the first introduction of <a href=\"https:\/\/docs.microsoft.com\/xamarin\/xamarin-forms\/app-fundamentals\/shell\/\"><code>Shell<\/code><\/a>, an application container that provides URI navigation and a quick way to implement flyout menus and tabs. To get started add <code>Shell<\/code> as the root element to your window in the <code>App.xaml.cs<\/code>. The typical pattern I follow is naming it &#8220;AppShell&#8221;, though you can name it as you wish.<\/p>\n<pre><code class=\"language-csharp\">protected override IWindow CreateWindow(IActivationState activationState)\r\n{\r\n    return new Microsoft.Maui.Controls.Window(\r\n        new AppShell()\r\n    );\r\n}<\/code><\/pre>\n<p>Now in your AppShell class start populating the menu with content using the type that represents the navigation you wish to display, either <code>FlyoutItem<\/code> or <code>Tab<\/code>. These are not UI controls, but rather represent the types that will create those UI controls. You can later style the controls with content templates which we&#8217;ll introduce in preview 6.<\/p>\n<pre><code class=\"language-xaml\">&lt;Shell xmlns=\"http:\/\/schemas.microsoft.com\/dotnet\/2021\/maui\" \r\n       xmlns:x=\"http:\/\/schemas.microsoft.com\/winfx\/2009\/xaml\"\r\n       xmlns:pages=\"clr-namespace:ControlGallery.Pages\"\r\n       Title=\"ControlGallery\"\r\n       x:Class=\"ControlGallery.AppShell\"&gt;\r\n\r\n    &lt;FlyoutItem Title=\"Margin and Padding\"&gt;\r\n        &lt;ShellContent Route=\"marginpadding\" \r\n                      ContentTemplate=\"{DataTemplate pages:ControlsPage}\" \/&gt;\r\n    &lt;\/FlyoutItem&gt;\r\n\r\n    &lt;FlyoutItem Title=\"ActivityIndicator\"&gt;\r\n        &lt;ShellContent Route=\"activityindicator\" \r\n                      ContentTemplate=\"{DataTemplate pages:ActivityIndicatorPage}\" \/&gt;\r\n    &lt;\/FlyoutItem&gt;\r\n\r\n    ...\r\n\r\n&lt;\/Shell&gt;<\/code><\/pre>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2021\/06\/maui-shell-catalyst.gif\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-33368\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2021\/06\/maui-shell-catalyst.gif\" alt=\"Image maui shell catalyst\" width=\"1322\" height=\"1080\" \/><\/a><\/p>\n<p>Get the very latest information about controls, layouts, and features on our <a href=\"https:\/\/github.com\/dotnet\/maui\/wiki\/Status\">.NET MAUI status page<\/a>.<\/p>\n<h2>Single Project Templates Updates<\/h2>\n<p>We have made progress in this release consolidating the multiple WinUI projects into one. Now when you <code>dotnet new maui<\/code> a project you&#8217;ll see two projects: the multi-targeted .NET MAUI project, and the WinUI project.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2021\/06\/maui-preview-5-solution.png\" alt=\"visual studio showing two projects\" \/><\/p>\n<p>Now to run the WinUI project you&#8217;ll have no confusion about which project to choose. This is one step closer to the final vision of having just one project that can build and deploy to all supported platforms. In order to support this, you&#8217;ll need to install these Project Reunion 0.8 (Preview) extensions for Visual Studio 16.11 Preview 2.<\/p>\n<ul>\n<li><a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=ProjectReunion.MicrosoftProjectReunionPreview\">Project Reunion (Preview) Extension<\/a><\/li>\n<li><a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=ProjectReunion.MicrosoftSingleProjectMSIXPackagingTools\">Single-project MSIX Packaging Tools (Preview)<\/a><\/li>\n<\/ul>\n<h2>Getting Started with .NET MAUI Preview 5<\/h2>\n<p>In this release we&#8217;ve enabled restoring your project without adding a custom NuGet source. Just create a new project and run it! To get all the latest pieces, we continue to recommend running the <code>maui-check<\/code> dotnet tool.<\/p>\n<p>To install:<\/p>\n<pre><code class=\"language-console\">$ dotnet tool install -g redth.net.maui.check<\/code><\/pre>\n<p>Now run and follow the updates to get .NET 6 Preview 5, platform SDKs, .NET MAUI, project templates, and even check your environment for 3rd party dependencies.<\/p>\n<pre><code class=\"language-console\">$ maui-check<\/code><\/pre>\n<p>If you wish to go step-by-step yourself, you can install everything individually with <a href=\"https:\/\/github.com\/dotnet\/maui-samples\/#installing-with-official-preview-installers\">these instructions<\/a>.<\/p>\n<p>Once installed, you&#8217;re ready to create a new app based on the preview 5 template.<\/p>\n<pre><code class=\"language-console\">$ dotnet new maui -n MauiFive<\/code><\/pre>\n<p>Open your new <code>MauiFive.sln<\/code> in Visual Studio 16.11 Preview 1 and run the platform of your choice!<\/p>\n<blockquote><p>Note: If you installed .NET 6 Preview 4 previously (either directly or by installing .NET MAUI), then you may run into issues installing and running .NET 6 Preview 5. See the <a href=\"https:\/\/github.com\/dotnet\/core\/blob\/main\/release-notes\/6.0\/known-issues.md#preview-5\" rel=\"noopener\" target=\"_blank\">.NET 6 Known Issues<\/a> for instructions on how to fix up your installation.<\/p><\/blockquote>\n<p>Eager to try <a href=\"https:\/\/visualstudio.microsoft.com\/vs\/preview\/vs2022\/\" rel=\"noopener\" target=\"_blank\">Visual Studio 2022 Preview 1<\/a>? Start exploring with the mobile platforms using the Android emulator and iOS with a remote iOS device, or connected Mac host. Be sure to disable XAML Hot Reload to avoid a type error, or stick with Visual Studio 2019 version 16.11 Preview 2. <\/p>\n<p>In the future, Project Reunion extensions will support Visual Studio 2022 and you&#8217;ll be able to use all the platforms on Windows.<\/p>\n<p>If you have existing .NET MAUI projects you wish to migrate to Preview 5, I recommend creating a new project like above and copying your files over to the multi-targeted project so you can avoid the trouble of reconciling the WinUI projects.<\/p>\n<p>For additional information about getting started with .NET MAUI, refer to our <a href=\"https:\/\/docs.microsoft.com\/dotnet\/maui\" rel=\"noopener\" target=\"_blank\">new documentation website<\/a>.<\/p>\n<h2>Feedback Welcome<\/h2>\n<p>Please let us know about your experiences using .NET MAUI Preview 5 to create new applications by engaging with us on GitHub at <a href=\"https:\/\/github.com\/dotnet\/maui\">dotnet\/maui<\/a>.<\/p>\n<p>For a look at what is coming in future releases, visit our <a href=\"https:\/\/github.com\/dotnet\/maui\/wiki\/roadmap\">product roadmap<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>.NET MAUI Preview 5 is now available. We have enabled animations and view transformations, completed the porting of several UI components, and introduced improvements to the single project templates.<\/p>\n","protected":false},"author":553,"featured_media":33367,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[685,7233],"tags":[],"class_list":["post-33359","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dotnet","category-maui"],"acf":[],"blog_post_summary":"<p>.NET MAUI Preview 5 is now available. We have enabled animations and view transformations, completed the porting of several UI components, and introduced improvements to the single project templates.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/33359","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/users\/553"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/comments?post=33359"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/33359\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media\/33367"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media?parent=33359"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/categories?post=33359"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/tags?post=33359"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}