3

I'm writing a Xamarin.Forms desktop application, and I'll ultimately want to target MacOS and Windows. Does Xamarin.Forms have any platform independent mechanisms which you can use to build the application menu (i.e. the one where you find "File", "Edit", "View", etc; and which appears in the MacOS menu bar at the top of the screen)? The most I've found is the Xamarin.Forms.Menu and Xamarin.Forms.MenuItem classes, but I'm not clear on what they actually do or how to use them.

Jwosty
  • 3,497
  • 2
  • 22
  • 50

1 Answers1

2

Although,Xamain forms can not directly use you said methods to do.

Package Microsoft.Toolkit.Uwp.UI.Controls 5.0.0 is not compatible with netstandard2.0 >>(.NETStandard,Version=v2.0).

However, add this NuGet Package to UWP, you can try to use custom ViewRenderer to do this.

https://learn.microsoft.com/en-us/windows/communitytoolkit/controls/menu

Code like this:

<Grid>
    <controls:Menu>
        <controls:MenuItem Name="FileMenu"
    controls:Menu.InputGestureText="Alt+F"
    Header="File">

            <MenuFlyoutSubItem Text="New">
                <MenuFlyoutItem controls:Menu.InputGestureText="Ctrl+Shift+N"
            Text="Project" />

                <MenuFlyoutItem controls:Menu.InputGestureText="Ctrl+N"
            Text="File" />
            </MenuFlyoutSubItem>
        </controls:MenuItem>
    </controls:Menu>
</Grid>

enter image description here

The final result is like this.

enter image description here

Junior Jiang
  • 12,430
  • 1
  • 10
  • 30
  • Good to know about that UWP control... so basically, a custom renderer is the way to go? – Jwosty Dec 13 '18 at 18:22
  • @Jwosty Answer is still creating a forms application, just doing a viewrenderer on UWP.(https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/custom-renderer/view). – Junior Jiang Dec 14 '18 at 01:13