Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 81 additions & 1 deletion docs/fundamentals/app-lifecycle.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "App lifecycle"
description: ".NET MAUI raises cross-platform lifecycle events when an app transitions between its different execution states."
ms.date: 08/30/2024
ms.date: 08/11/2026
---

# App lifecycle
Expand Down Expand Up @@ -378,6 +378,86 @@ namespace PlatformLifecycleDemo
}
```

::: moniker range=">=net-maui-11.0"

#### Handle AppInstance activation

On Windows, the `OnAppInstanceActivated` lifecycle hook receives the initial <xref:Microsoft.Windows.AppLifecycle.AppInstance> activation and subsequent file, protocol, and redirected activations. Its handler receives an <xref:Microsoft.Windows.AppLifecycle.AppActivationArguments> object and returns a `bool` that indicates whether the activation has been handled.

You can use this hook to implement a single-instance app. Register an app key with <xref:Microsoft.Windows.AppLifecycle.AppInstance.FindOrRegisterForKey%2A>, and redirect activations from other instances to the registered instance:

```csharp
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Maui.LifecycleEvents;
using Microsoft.Windows.AppLifecycle;

namespace PlatformLifecycleDemo;

public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.ConfigureLifecycleEvents(events =>
{
#if WINDOWS
events.AddWindows(windows => windows
.OnAppInstanceActivated(HandleAppInstanceActivated));
#endif
});

return builder.Build();
}

#if WINDOWS
static bool HandleAppInstanceActivated(
Microsoft.UI.Xaml.Application application,
AppActivationArguments args)
{
AppInstance keyInstance =
AppInstance.FindOrRegisterForKey("PlatformLifecycleDemo");

if (!keyInstance.IsCurrent)
{
_ = RedirectActivationAndExitAsync(application, keyInstance, args);
return true;
}

if (Application.Current?.Windows.FirstOrDefault() is Window window)
{
Application.Current.ActivateWindow(window);
}

return false;
}

static async Task RedirectActivationAndExitAsync(
Microsoft.UI.Xaml.Application application,
AppInstance keyInstance,
AppActivationArguments args)
{
try
{
await keyInstance.RedirectActivationToAsync(args).AsTask();
}
finally
{
application.Exit();
}
}
#endif
}
```

Returning `true` from the transient instance marks the activation as handled and prevents it from creating a window. Always await <xref:Microsoft.Windows.AppLifecycle.AppInstance.RedirectActivationToAsync%2A> before exiting that app instance so that the running instance can consume the activation.

.NET MAUI uses this activation lifecycle to support <xref:Microsoft.Maui.Authentication.WebAuthenticator> callbacks on Windows. If your app registers its own `AppInstance` key, it owns activation routing and must redirect every external activation, including protocol activations, to the instance that started the authentication operation.

::: moniker-end

### Retrieve the Window object

Platform code can retrieve the app's `Window` object from platform lifecycle events, with the `GetWindow` extension method:
Expand Down
16 changes: 15 additions & 1 deletion docs/platform-integration/device-media/picker.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "Media picker for photos and videos"
description: "Learn how to use the IMediaPicker interface in the Microsoft.Maui.Media namespace, to prompt the user to select or take a photo or video"
ms.date: 07/08/2026
ms.date: 08/06/2026
no-loc: ["Microsoft.Maui", "Microsoft.Maui.Media", "MediaPicker"]
---

Expand Down Expand Up @@ -192,6 +192,20 @@ foreach (var file in results)

::: moniker range=">=net-maui-11.0"

### Save captured media to the gallery

The `MediaPickerOptions.SaveToGallery` property controls whether a captured photo or video is also saved to the device's gallery. The default value is `false`, and the property only applies to <xref:Microsoft.Maui.Media.IMediaPicker.CapturePhotoAsync%2A> and <xref:Microsoft.Maui.Media.IMediaPicker.CaptureVideoAsync%2A> operations. It's ignored by media pick operations.

```csharp
FileResult? photo = await MediaPicker.Default.CapturePhotoAsync(
new MediaPickerOptions
{
SaveToGallery = true
});
```

Saving captured media to the gallery is supported on Android, iOS, and Mac Catalyst. On iOS and Mac Catalyst, the `NSPhotoLibraryAddUsageDescription` key must be present in *Info.plist*. On Android versions earlier than API 29, the `WRITE_EXTERNAL_STORAGE` permission is required. The property is ignored on Windows and Tizen.

### Recover interrupted Android media picker operations

On Android, the system can destroy and recreate your app while the camera or photo picker UI is in front. If the original media picker task is gone when your app resumes, use the Android-only recovery APIs to retrieve any accepted results.
Expand Down
32 changes: 31 additions & 1 deletion docs/user-interface/controls/window.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "Window"
description: "Learn how to use the .NET MAUI Window class to create, configure, show, and manage multi-window apps."
ms.date: 08/19/2025
ms.date: 08/06/2026
---

# Window
Expand All @@ -17,6 +17,9 @@ The .NET Multi-platform App UI (.NET MAUI) <xref:Microsoft.Maui.Controls.Window>
- <xref:Microsoft.Maui.Controls.Window.MinimumHeight>, of type `double`, represents the minimum height of the window on desktop platforms. Valid values are between 0 and `double.PositiveInfinity`.
- <xref:Microsoft.Maui.Controls.Window.MinimumWidth>, of type `double`, represents the minimum width of the window on desktop platforms. Valid values are between 0 and `double.PositiveInfinity`.
- <xref:Microsoft.Maui.Controls.Window.Overlays>, of type `IReadOnlyCollection<IWindowOverlay>`, represents the collection of window overlays.
::: moniker range=">=net-maui-11.0"
- `Window.StatusBarTheme`, of type `StatusBarTheme`, controls the appearance of the status bar icons on Android 6.0 (API 23) or later and iOS.
::: moniker-end
- <xref:Microsoft.Maui.Controls.Page>, of type <xref:Microsoft.Maui.Controls.Page>, indicates the page being displayed by the window. This property is the content property of the <xref:Microsoft.Maui.Controls.Window> class, and therefore does not need to be explicitly set.
- <xref:Microsoft.Maui.Controls.Window.Title>, of type `string`, represents the title of the window.
- <xref:Microsoft.Maui.Controls.Window.Width>, of type `double`, specifies the width of the window on Windows.
Expand Down Expand Up @@ -51,6 +54,33 @@ The <xref:Microsoft.Maui.Controls.Window> class also defines the following modal

The <xref:Microsoft.Maui.Controls.VisualElement> class has a `Window` property that exposes the parent <xref:Microsoft.Maui.Controls.Window> object. This property can be accessed from any page, layout, or view, to manipulate <xref:Microsoft.Maui.Controls.Window> objects.

::: moniker range=">=net-maui-11.0"

## Set the status bar theme

On Android 6.0 (API 23) or later and iOS, set `Window.StatusBarTheme` to control the appearance of the operating system-drawn status bar icons independently of the app theme. The default value, `StatusBarTheme.Default`, follows the current app theme.

Choose the value that matches the surface behind the status bar:

- `StatusBarTheme.Light` indicates a light surface and displays dark icons.
- `StatusBarTheme.Dark` indicates a dark surface and displays light icons.

For example, if the app uses a dark header behind the status bar while the rest of the app uses a light theme, set `StatusBarTheme` to `Dark`:

```csharp
protected override Window CreateWindow(IActivationState? activationState)
{
return new Window(new AppShell())
{
StatusBarTheme = StatusBarTheme.Dark
};
}
```

This property has no effect on Android versions earlier than API 23, Mac Catalyst, Windows, or Tizen.

::: moniker-end

## Create a Window

::: moniker range="=net-maui-8.0"
Expand Down
Loading