问题
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.
回答1:
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://docs.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>
The final result is like this.
来源:https://stackoverflow.com/questions/53749773/xamarin-forms-platform-indepenent-application-menu