What happened to MenuItems in SHell?

xeg12xeg12 Member ✭✭

I have been using the last few previews of Forms 4 and had a nice Flyout section with selectable items created from a database followed by MenuItems for things such as settings, About etc.
The release version has broken this with the removal of MenuItems.
WHY was this done? MenuItems provides flexibility when I do not want to have tab items, where I want a modal page or where I want a conditional page (I choose in a bound command).

Tagged:

Best Answer

Answers

  • JarvanJarvan Member, Xamarin Team Xamurai
    edited May 24

    @xeg12
    Have you faced an error like 'A value of type 'MenuItem' cannot be added to a collection or dictionary of type xxx' ?

    This is just an intellisense error that's being worked on. It builds and runs without any issues. Deploy your code and it'll not be terminated.
    See the tutorial: https://github.com/MicrosoftDocs/xamarin-docs/issues/1711#issuecomment-495128674

  • xeg12xeg12 Member ✭✭
    edited May 24

    This is NOT just intellisense.
    My MenuItems are defined in the XAML for the shell.
    When I uncomment them and recompile I get an error:

    Error XLS0415 The attachable property 'MenuItems' was not found in type 'Shell'. GenList MainShell.xaml

    Therefore I am unable to continue without commenting out the MenuItems

  • JarvanJarvan Member, Xamarin Team Xamurai

    Please post the relevant code which will help to reproduce the issue.

  • xeg12xeg12 Member ✭✭

    Add this to the XAML for - make it the last entry before
    Uncomment it and it does not compile with the release version of Forms 4 using VS 2019 enterprise preview. The same happens in VS 2017 Pro

    <!--<Shell.MenuItems>
    
        <MenuItem
            BindingContext="{x:Reference mainShell}"
            Command="{Binding BindingContext.BackupListsCommand}"
            CommandParameter="Backup"
            Text="Backup"
            Icon="backup.png"
            />
    
        <MenuItem
            BindingContext="{x:Reference mainShell}"
            Command="{Binding BindingContext.SettingsCommand}"
            CommandParameter="1"
            Text="Settings"
            Icon="Settings.png"/>
    
        <MenuItem
            BindingContext="{x:Reference mainShell}"
            Command="{Binding BindingContext.AboutCommand}"
            CommandParameter="2"
            Text="About" 
            Icon="About.png"/>
    </Shell.MenuItems>-->
    
  • xeg12xeg12 Member ✭✭
    edited May 24

    By the way the 4.0.0 API changes for Release documentation says for Shell "BindableProperty MenuItemsProperty" and "MenuItemCollection MenuItems" were removed.
    Can't post link to the documentation.

  • xeg12xeg12 Member ✭✭

    That works. First time I tried it I got an error but it did not compile. This time I compiled and the errors went away.

    I did not see any notification of this change. Why was such a significant change not made in a prerelease which would have provided much better documentation?

  • TaylorDTaylorD USMember ✭✭✭

    Not sure. I don't personally use Shell, just relayed on what I read in the documentation I found.

    Glad it's working for you now!

  • xeg12xeg12 Member ✭✭
    edited May 24

    Well it sort of worked ….
    MenuItem won't accept a TabIndex (it won't compile) so the menuitems are always before the database-derived entries.
    I did try giving the database-derived entries negative TabIndex entries but that didn't work.

    On top of which I think the release version of Forms 4 has created a new bug on my add new item form! Just going to revert to the last Pre-release to confirm. It's one of those days!

  • xeg12xeg12 Member ✭✭

    Yup, prerelease 10 stops the error.
    It is a NullReferenceException in the Forms code. It happens sometime after the Appearing event on my create new item page.

  • TaylorDTaylorD USMember ✭✭✭
    edited May 24

    If you can create a small reproduction solution that indicates the issue, I suggest posting an issue on their GitHub with the steps/VS solution that indicates the error. (If an issue doesn't exist for it already)

  • wagenheimerwagenheimer Member ✭✭

    How to create MenuItems by code?

    I can't add them to Shell.Current.Items, it fails with "'ShellItem.implicit operator ShellItem(MenuItem)' is obsolete: 'Please dont use this in core code... its SUPER hard to debug when this happens'"

  • wagenheimerwagenheimer Member ✭✭
    edited September 18

    I found the answer, you should use new MenuShellItem(menuitem).

    But MenuShellItem is declared as internal, it should be public.

    In documentation (https://docs.microsoft.com/en-us/dotnet/api/xamarin.forms.menushellitem?view=xamarin-forms) it supposed to be public, but in Source Code (https://github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.Core/Shell/MenuShellItem.cs) isn't.

Sign In or Register to comment.