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
105 changes: 101 additions & 4 deletions docs/fundamentals/shell/custom-handlers.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
---
title: ".NET MAUI Shell custom handlers"
description: "Learn how to customize the appearance and behavior of a .NET MAUI Shell app using platform-specific handlers."
ms.date: 07/28/2026
ms.date: 10/08/2026
ai-usage: ai-assisted
---

# .NET MAUI Shell custom handlers
Expand All @@ -13,7 +14,7 @@ ms.date: 07/28/2026
.NET MAUI Shell applications are highly customizable through the properties and methods that the various Shell classes expose. However, it's also possible to create custom handlers when more extensive platform-specific customizations are required. Custom handlers can be registered conditionally for a single platform, while allowing the default behavior on other platforms.

> [!NOTE]
> Shell custom handlers are currently supported on Android in .NET MAUI 11 and later. iOS and Mac Catalyst continue to use the legacy `ShellRenderer`.
> Shell uses handlers by default on Android in .NET MAUI 11 and later. On iOS and Mac Catalyst, the compatibility `ShellRenderer` remains the default, but you can opt in to the Shell handler implementation.

## Android handler customization

Expand All @@ -24,8 +25,8 @@ Starting in .NET MAUI 11, Shell on Android uses a handler-based architecture by
The process for creating a custom Shell handler on Android is:

1. Create a subclass of `ShellHandler`, `ShellItemHandler`, or `ShellSectionHandler`.
2. Override the required methods to perform the customization.
3. Register the handler in `MauiProgram.cs`.
1. Override the required methods to perform the customization.
1. Register the handler in `MauiProgram.cs`.

The following handler classes expose overridable members on Android:

Expand Down Expand Up @@ -112,4 +113,100 @@ builder
});
```

## iOS and Mac Catalyst handler customization

In .NET MAUI 11, enable the Shell handler implementation on iOS and Mac Catalyst by setting the `UseiOSShellHandler` MSBuild property to `true` in your app's project file:

```xml
<PropertyGroup>
<UseiOSShellHandler>true</UseiOSShellHandler>
</PropertyGroup>
```

This property sets the `Microsoft.Maui.RuntimeFeature.IsiOSShellHandlerEnabled` <xref:System.AppContext> switch, which defaults to `false`. When enabled, the built-in registration adds the complete Shell handler hierarchy:

| Control | Handler | Responsibility |
| --- | --- | --- |
| `Shell` | `ShellHandler` | Root view controller, flyout presentation, and item transitions. |
| `ShellItem` | `ShellItemHandler` | Tab-bar controller and section selection. |
| `ShellSection` | `ShellSectionHandler` | Navigation controller and navigation stack. |
| `ShellContent` | `ShellContentHandler` | Forward content changes to the owning section handler. |

All four handler types are in the `Microsoft.Maui.Controls.Handlers` namespace. You don't need to register them manually when you use the project property.

To return to the compatibility renderer with the default registrations, remove the property or set it to `false`. Existing custom `ShellRenderer`, `ShellItemRenderer`, and `ShellSectionRenderer` implementations remain supported. If you manually register custom handlers, also remove or replace those registrations when returning to the renderer.

### Create a custom Apple Shell handler

Subclass `ShellHandler` and override its protected virtual factory methods to customize appearance trackers or other Shell components:

| Factory method | Customization |
| --- | --- |
| `CreateNavBarAppearanceTracker` | Navigation-bar appearance. |
| `CreateTabBarAppearanceTracker` | Tab-bar appearance. |
| `CreatePageRendererTracker` | Page navigation-bar and toolbar tracking. |
| `CreateShellFlyoutContentRenderer` | Flyout content. |
| `CreateShellItemRenderer` | Item handler integration. |
| `CreateShellSectionRenderer` | Section handler integration. |
| `CreateShellItemTransition` | Transitions between Shell items. |
| `CreateShellSearchResultsRenderer` | Search results presentation. |

Some factory names and return types retain renderer terminology for compatibility. The default item and section factories resolve `ShellItemHandler` and `ShellSectionHandler` from the handler registry and adapt them to the compatibility interfaces. Register a subclass for `ShellItem` or `ShellSection` to customize a child handler.

Unlike the compatibility renderers, `ShellHandler`, `ShellItemHandler`, and `ShellSectionHandler` own native view controllers instead of inheriting from them. When migrating a renderer customization, move tracker factory overrides to `ShellHandler`, and adapt code that depends on native view-controller overrides.

For example, the following classes add a border to the tab bar. Compile this code only for iOS and Mac Catalyst:

```csharp
#if IOS || MACCATALYST
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.Handlers;
using Microsoft.Maui.Controls.Platform.Compatibility;
using UIKit;

namespace MyApp.Platforms.Apple;

public class MyShellHandler : ShellHandler
{
protected override IShellTabBarAppearanceTracker CreateTabBarAppearanceTracker()
{
return new MyShellTabBarAppearanceTracker();
}
}

public class MyShellTabBarAppearanceTracker : ShellTabBarAppearanceTracker
{
public override void SetAppearance(
UITabBarController controller,
ShellAppearance appearance)
{
base.SetAppearance(controller, appearance);

controller.TabBar.Layer.BorderColor = UIColor.Red.CGColor;
controller.TabBar.Layer.BorderWidth = 1;
}
}
#endif
```

### Register the Apple handler

After enabling `UseiOSShellHandler`, register your custom handler after `UseMauiApp` in `MauiProgram.cs`:

```csharp
using Microsoft.Maui.Controls;

var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.ConfigureMauiHandlers(handlers =>
{
#if IOS || MACCATALYST
handlers.AddHandler<Shell, MyApp.Platforms.Apple.MyShellHandler>();
#endif
});
```

This replaces only the root Shell handler registration. The project property supplies the other three built-in registrations.

::: moniker-end
26 changes: 25 additions & 1 deletion docs/user-interface/controls/carouselview/index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
---
title: "CarouselView"
description: "The .NET MAUI CarouselView is a view for presenting data in a scrollable layout, where users can swipe to move through a collection of items."
ms.date: 08/19/2025
ms.date: 10/08/2026
ai-usage: ai-assisted
---

# CarouselView
Expand Down Expand Up @@ -37,3 +38,26 @@ builder.ConfigureMauiHandlers(handlers =>
```

::: moniker-end

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

## Migrate custom handlers on iOS and Mac Catalyst

In .NET MAUI 11, legacy Apple handler APIs in the `Microsoft.Maui.Controls.Handlers.Items` namespace, including `CarouselViewHandler`, produce obsolete warnings on iOS and Mac Catalyst. The <xref:Microsoft.Maui.Controls.CarouselView> control itself is not obsolete. The warnings don't apply to the `CarouselViewHandler` on Android or Windows.

If you registered the legacy handler only to restore .NET 9 behavior, remove that registration to use the default optimized handler. To change an explicit registration to the optimized handler, use:

```csharp
#if IOS || MACCATALYST
builder.ConfigureMauiHandlers(handlers =>
{
handlers.AddHandler<Microsoft.Maui.Controls.CarouselView, Microsoft.Maui.Controls.Handlers.Items2.CarouselViewHandler2>();
});
#endif
```

For a custom handler, derive from `Microsoft.Maui.Controls.Handlers.Items2.CarouselViewHandler2` instead of the legacy `CarouselViewHandler`, and register your subclass in place of `CarouselViewHandler2`. Update mapper customizations to use the optimized handler's mappers. For guidance on legacy controller, cell, and layout customizations, see [Migrate custom CollectionView handlers on iOS and Mac Catalyst](~/user-interface/controls/collectionview/index.md#migrate-custom-handlers-on-ios-and-mac-catalyst).

The [legacy handler registration](#revert-to-net-9-behavior) remains available as a temporary compatibility opt-out while you migrate. In .NET MAUI 11, this registration produces obsolete warnings on iOS and Mac Catalyst.

::: moniker-end
24 changes: 23 additions & 1 deletion docs/user-interface/controls/collectionview/index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
---
title: "CollectionView"
description: "The .NET MAUI CollectionView displays a scrollable list of selectable data items, using different layout specifications."
ms.date: 07/08/2026
ms.date: 10/08/2026
ai-usage: ai-assisted
---

# CollectionView
Expand Down Expand Up @@ -38,12 +39,33 @@ builder.ConfigureMauiHandlers(handlers =>

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

## Migrate custom handlers on iOS and Mac Catalyst

In .NET MAUI 11, legacy Apple handler APIs in the `Microsoft.Maui.Controls.Handlers.Items` namespace, including `CollectionViewHandler`, produce obsolete warnings on iOS and Mac Catalyst. The <xref:Microsoft.Maui.Controls.CollectionView> control itself is not obsolete. The warnings apply to the legacy handler APIs, not to every type in the `Items` namespace or to the handlers on other platforms.

If you registered the legacy handler only to restore .NET 9 behavior, remove that registration to use the default optimized handler. To change an explicit registration to the optimized handler, use:

```csharp
#if IOS || MACCATALYST
builder.ConfigureMauiHandlers(handlers =>
{
handlers.AddHandler<Microsoft.Maui.Controls.CollectionView, Microsoft.Maui.Controls.Handlers.Items2.CollectionViewHandler2>();
});
#endif
```

For a custom handler, derive from `Microsoft.Maui.Controls.Handlers.Items2.CollectionViewHandler2` instead of the legacy `CollectionViewHandler`, and register your subclass in place of `CollectionViewHandler2`. Update mapper customizations to use the optimized handler's mappers. Legacy controller, cell, and layout extension points don't all have a one-to-one replacement. Adapt those customizations to the `Items2` handler and native `UICollectionViewLayout` extension points.

The [legacy handler registration](#revert-to-net-9-behavior) remains available as a temporary compatibility opt-out while you migrate. In .NET MAUI 11, this registration produces obsolete warnings on iOS and Mac Catalyst.

## Windows CollectionView handler in .NET 11

In .NET MAUI 11, Windows uses the `Microsoft.Maui.Controls.Handlers.Items2.CollectionViewHandler2` handler for <xref:Microsoft.Maui.Controls.CollectionView> by default. The handler is controlled by the `Microsoft.Maui.RuntimeFeature.IsWindowsCollectionView2HandlerEnabled` <xref:System.AppContext> switch, which is on by default. The `UseWindowsCollectionView2Handler` MSBuild property maps to this switch.

This WinUI `ItemsRepeater`-based handler improves virtualization and scrolling behavior, and aligns the Windows <xref:Microsoft.Maui.Controls.CollectionView> architecture with the optimized handlers on other platforms. Selection visuals are also different from the legacy Windows handler: selected items are highlighted with a border that wraps the item, and the multiple-selection UI differs from the previous `ListView`-based handler.

The legacy Windows `CollectionViewHandler` and its handler APIs remain supported and are not obsolete in .NET MAUI 11.

If your app depends on legacy Windows <xref:Microsoft.Maui.Controls.CollectionView> behavior or custom handler assumptions, temporarily opt out while migrating by setting the `UseWindowsCollectionView2Handler` MSBuild property to `false` in your project file:

```xml
Expand Down
Loading