dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
21.99k stars 1.72k forks source link

VisualDiagnostics.VisualTreeChanged returns null parent elements, -1 Child Index Values, for new items. #22986

Open drasticactions opened 3 months ago

drasticactions commented 3 months ago

Description

スクリーンショット 2024-06-12 14 14 45

Some parent elements being sent to VisualDiagnostics.VisualTreeChanged for new items are null, resulting in -1 Child Index values. Checking the children values, the parent is null there too. This seems to happen consistently for

As far as I can tell, this is not a regression. I think it's always done from early in MAUIs history. This doesn't break tools like XAML Hot Reload, but we need to recalculate the visual tree for these elements and that can be costly to do.

Steps to Reproduce

  1. Clone https://github.com/davidortinau/AllTheLists
  2. Load the App in VS/VSCode
  3. Open the XAML/C# Hot Reload Log list
  4. See the logs for ChildIndex <= -1. These are due to null parents being passed in through the MAUI EventHandler.
  5. Or put a breakpoint in VisualDiagnostics.VisualTreeChanged in MAUI and see that parent is null.

Or

  1. Create a new app with two pages
  2. Hook into VisualDiagnostics.VisualTreeChanged

Link to public reproduction project repository

https://github.com/davidortinau/AllTheLists

Version with bug

8.0.40 SR5

Is this a regression from previous behavior?

No, this is something new

Last version that worked well

Unknown/Other

Affected platforms

iOS, Android, Windows, macOS

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

No response

github-actions[bot] commented 3 months ago

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.