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
22.28k stars 1.76k forks source link

Shell MenuItemTemplate Broken #25190

Open david-maw opened 1 month ago

david-maw commented 1 month ago

Description

I'm not sure exactly how it is broken but the symptom seems to be that MenuItem names vanish in the Shell flyout - whether they are not there or are white on a white background I have not investigated.

Steps to Reproduce

  1. Download the repo
  2. Build and run the main branch (built with RC2 but there was no dropdown for that below, so I used RC1), you'll see:
  3. Image
  4. What you should see is:
  5. Image

Link to public reproduction project repository

https://github.com/david-maw/ShellTemplate9.git

Version with bug

9.0.0-rc.1.24453.9

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

8.0.91 SR9.1

Affected platforms

Android, Windows, I was not able test on other platforms

Affected platform versions

Windows 11, Android 14

Did you find any workaround?

Sort of, use x:DataType="BaseShellItem" in both templates, which seems like it should not work for the MenuItemTemplate because BaseShellItem doesn't have a "Text" property and a build does indeed generate a warning to that effect but it works anyway.

Relevant log output

No response

similar-issues-ai[bot] commented 1 month ago

We've found some similar issues:

If any of the above are duplicates, please consider closing this issue out and adding additional context in the original issue.

Note: You can give me feedback by πŸ‘ or πŸ‘Ž this comment.

jaosnz-rep commented 1 month ago

I can repro it at Windows platform on the latest 17.12.0 Preview 2.1(9.0.0-rc.1.24453.9), but it works fine on 8.0.91.

Foda commented 1 month ago

Hello! In NET 9 we've made DataType more robust in checking if the specified type matches the assigned BindingContext during the binding step (https://github.com/dotnet/maui/blob/net9.0/src/Controls/src/Core/Binding.cs#L129-L137). In this case, MenuItem isn't actually a ShellItem -- it gets implicitly converted to MenuShellItem which isn't a public class.

For now, just remove the x:DataType on the MenuItem style.

Foda commented 1 month ago

Just to add to your workaround, if you use BaseShellItem as the DataType, you can use the Title property. MenuShellItem internally maps Text to Title

david-maw commented 1 month ago

Yep, that improvement to my workaround did the trick, thanks @Foda , this is now a low priority problem for me.