Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App crashes when navigating from TabbedPage to another TabbedPage #22131

Closed
davishoang96 opened this issue Apr 30, 2024 · 5 comments
Closed

App crashes when navigating from TabbedPage to another TabbedPage #22131

davishoang96 opened this issue Apr 30, 2024 · 5 comments
Labels
area-controls-tabbedpage TabbedPage high It doesn't work at all, crashes or has a big impact. platform/windows 🪟 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Milestone

Comments

@davishoang96
Copy link

Description

I'm using MainPage = new NavigationPage(new MainPage()); instead of AppShell() The app crashes when navigating from one TabbedPage to another.

Exception: Microsoft.UI.Xaml.Controls.Frame.NavigationFailed was unhandled.
Example apps: MauiAppTabbedPage.zip

Recording.2024-04-30.124611.mp4

Screenshot 2024-04-30 124814

Steps to Reproduce

No response

Link to public reproduction project repository

No response

Version with bug

8.0.21 SR4.1

Is this a regression from previous behavior?

Yes, this used to work in Xamarin.Forms

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

WinUI

Did you find any workaround?

No response

Relevant log output

Microsoft.UI.Xaml.Controls.Frame.NavigationFailed was unhandled.
@davishoang96 davishoang96 added the t/bug Something isn't working label Apr 30, 2024
@Zhanglirong-Winnie Zhanglirong-Winnie added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels Apr 30, 2024
@Zhanglirong-Winnie
Copy link

Verified this issue with Visual Studio 17.10 Preview 5 (8.0.21&8.0.7). Can repro on windows platform with sample project. Android platform works fine.

@PureWeen PureWeen added the high It doesn't work at all, crashes or has a big impact. label Apr 30, 2024
@PureWeen PureWeen added this to the Backlog milestone Apr 30, 2024
@PureWeen
Copy link
Member

PureWeen commented May 2, 2024

/similarissues

Copy link
Contributor

github-actions bot commented May 2, 2024

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

@AppAffection
Copy link

Idk if it is of any help but we have testers who can switch between tabs just fine all day long without it crashing and then we have testers that it consistently crashes on when changing tabs more than once. We have looked at every difference in the machines that we can think of like font scaling, light and dark themes, Windows versions, etc and the only difference we can say for sure that we see is the ones using Windows Enterprise it does not crash on but the ones using Windows Pro it crashes on. Maybe that is totally a coincidence but we have been trying to find some reason for it not crashing for some and crashing for others. I just wanted to share in case it helps speed up a fix for this.

@PureWeen
Copy link
Member

Duplicate of #22790

@PureWeen PureWeen marked this as a duplicate of #22790 Nov 18, 2024
Foda added a commit that referenced this issue Nov 19, 2024
### 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
@github-actions github-actions bot locked and limited conversation to collaborators Dec 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-controls-tabbedpage TabbedPage high It doesn't work at all, crashes or has a big impact. platform/windows 🪟 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants