.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
Перейти к файлу
Mike Corsaro fa519a2c9c
[Windows] Fix crash when navigating pages (#25740)
### Description of Change

Fixes a long-standing crash when navigating pages:

1. Manually clear the `ContentPresenter.Content` property.

When navigating pages it was discovered that the `Content` property of
the `ContentPresenter` sometimes was not being detached from the parent
`ContentPresenter` (the `ContentPresenter` itself does detach from the
Page). A workaround for this was to manually clear the `Content`
property.

**The actual cause of this bug:** I suspect that something causing the
lifecycle tracking to be messed up. I'm still not sure what this is, but
for now this will help our customers more than nothing.

## Workaround

The following can be used as a workaround. Place it in the `Loaded`
event for your `AppShell`:

```csharp
private void AppShell_Loaded(object? sender, EventArgs e)
{
    Loaded -= AppShell_Loaded;

#if WINDOWS
    if (Handler != null && Handler.PlatformView is ShellView shellView &&
        shellView.Content is MauiNavigationView nv &&
        nv.Content is Microsoft.UI.Xaml.Controls.Frame frame)
    {
        frame.Navigating += (s, e) =>
        {
            if (frame.Content is Microsoft.UI.Xaml.Controls.Page page)
            {
                page.Unloaded += PageUnloaded;

                void PageUnloaded(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
                {
                    page.Unloaded -= PageUnloaded;
                    if (page.Content is Microsoft.UI.Xaml.Controls.ContentPresenter presenter)
                    {
                        presenter.Content = null;
                    }
                };
            }
        };
    }
#endif
}
```

### Issues Fixed

Fixes #22790 #18441 #22131
2024-11-19 09:35:25 -08:00
.config
.github
.vscode
Assets
docs
eng
loc
src
.editorconfig
.gitattributes
.gitconfig
.gitignore
Directory.Build.Override.props.in
Directory.Build.props
Directory.Build.targets
LICENSE.txt
Microsoft.Maui-dev.sln
Microsoft.Maui-mac.slnf
Microsoft.Maui-vscode.sln
Microsoft.Maui-windows.slnf
Microsoft.Maui.BuildTasks.slnf
Microsoft.Maui.Graphics.slnf
Microsoft.Maui.LegacyControlGallery.slnf
Microsoft.Maui.Packages-mac.slnf
Microsoft.Maui.Packages.slnf
Microsoft.Maui.Samples.slnf
Microsoft.Maui.sln
NuGet.config
README.md
SECURITY.md
THIRD-PARTY-NOTICES.TXT
build.cake
build.cmd
build.ps1
build.sh
cSpell.json
dotnet-local.cmd
dotnet-local.sh
global.json
maui.code-workspace
omnisharp.json

README.md

.NET Multi-platform App UI (.NET MAUI)

Build Status Build Status

.NET Multi-platform App UI (.NET MAUI) is a cross-platform framework for creating mobile and desktop apps with C# and XAML. Using .NET MAUI, you can develop apps that can run on Android, iOS, iPadOS, macOS, and Windows from a single shared codebase.

Getting Started

Overview

.NET Multi-platform App UI (.NET MAUI) is the evolution of Xamarin.Forms that expands capabilities beyond mobile Android and iOS into desktop apps for Windows and macOS. With .NET MAUI, you can build apps that perform great for any device that runs Windows, macOS, Android, & iOS from a single codebase. Coupled with Visual Studio productivity tools and emulators, .NET and Visual Studio significantly speed up the development process for building apps that target the widest possible set of devices. Use a single development stack that supports the best of breed solutions for all modern workloads with a unified SDK, base class libraries, and toolchain. Read More

.NET MAUI Weather App on all platforms

Current News

Follow the .NET MAUI Blog and visit the News wiki page for more news and updates.

FAQs

Do you have questions? Do not worry, we have prepared a complete FAQ answering the most common questions.

How to Engage, Contribute, and Give Feedback

Some of the best ways to contribute are to try things out, file issues, join in design conversations, and make pull-requests. Proposals for changes specific to MAUI can be found here for discussion.

See CONTRIBUTING, CODE-OF-CONDUCT and the Development Guide.