Xamarin.Forms: Platform-indepenent application menu

為{幸葍}努か 提交于 2021-02-19 04:39:27

问题


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>

enter image description here

The final result is like this.



来源:https://stackoverflow.com/questions/53749773/xamarin-forms-platform-indepenent-application-menu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!