Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

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).


Best Answer


  • JarvanJarvan Member, Xamarin Team Xamurai
    edited May 2019

    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:

  • xeg12xeg12 Member ✭✭
    edited May 2019

    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

            BindingContext="{x:Reference mainShell}"
            Command="{Binding BindingContext.BackupListsCommand}"
            BindingContext="{x:Reference mainShell}"
            Command="{Binding BindingContext.SettingsCommand}"
            BindingContext="{x:Reference mainShell}"
            Command="{Binding BindingContext.AboutCommand}"
  • xeg12xeg12 Member ✭✭
    edited May 2019

    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 2019

    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 2019

    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 2019

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

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

    In documentation ( it supposed to be public, but in Source Code ( isn't.

Sign In or Register to comment.