.NET MAUI Multi Window support

.NET MAUI Multi Window support

30 December 2021

.NET MAUI/Xamarin

Buy Me A Coffee

Howdy! 👋 It is almost 2022 and .NET MAUI team non-stop delivers new features for the upcoming MAUI year!

.NET MAUI Preview 11 was silently released (release notes) with Multi-Window support! Let's see how to add this cool feature to your application.

  1. Run dotnet workload update to update to the latest .NET MAUI Preview version. We need at least Preview 11.
  2. To open the window we need just 2 lines of code: the first line initializes a new window with a Page inside, and the second line just opens the window:
var newWindow = new Window(new SecondPage());
Application.Current?.OpenWindow(newWindow);
  1. Closing the window is even simpler - we need just 1 line of code.

To close the current window call the next command:

Application.Current?.CloseWindow(GetParentWindow());

To close a specific window pass the instance of that window to the method:

var myLastWindow = Application.Current?.Windows.Last();
Application.Current?.CloseWindow(myLastWindow);

Platform configurations

iOS/MacCatalyst

  1. Create and register SceneDelegate
[Register(nameof(SceneDelegate))]
public class SceneDelegate : MauiUISceneDelegate
{
}
  1. Open Info.plist and add the next content to the end of the file:
<key>UIApplicationSceneManifest</key>
<dict>
	<key>UIApplicationSupportsMultipleScenes</key>
	<true/>
	<key>UISceneConfigurations</key>
	<dict>
		<key>UIWindowSceneSessionRoleApplication</key>
		<array>
			<dict>
				<key>UISceneConfigurationName</key>
				<string>__MAUI_DEFAULT_SCENE_CONFIGURATION__</string>
				<key>UISceneDelegateClassName</key>
				<string>SceneDelegate</string>
			</dict>
		</array>
	</dict>
</dict>

MAUI Multi Window on iOS

Multi-Window on iOS

MAUI Multi Window on macOS

Multi-Window on macOS

The full code can be found on GitHub.

Happy holidays! 🎄🎁

Buy Me A Coffee

Related:

Create custom animations using .NET MAUI CommunityToolkit

This article describes how to leverage .NET MAUI CommunityToolkit BaseAnimation and AnimationBehavior to create and apply animation.

.NET MAUI Push Notifications using Azure Notification Hub. Part 2. Setup .NET MAUI

The article demonstrates how to add push notifications to .NET MAUI application using Azure Notification Hub.

An unhandled error has occurred. Reload

🗙