Xamarin.Forms:独立于平台的应用程序菜单 [英] Xamarin.Forms: Platform-indepenent application menu

查看:39
本文介绍了Xamarin.Forms:独立于平台的应用程序菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写 Xamarin.Forms 桌面应用程序,我最终希望面向 MacOS 和 Windows.Xamarin.Forms 是否有任何可用于构建应用程序菜单的独立于平台的机制(即,您可以找到文件"、编辑"、查看"等;并且出现在顶部的 MacOS 菜单栏中的机制)屏幕)?我发现最多的是 Xamarin.Forms.MenuXamarin.Forms.MenuItem 类,但我不清楚它们实际做什么或如何使用

解决方案

虽然,Xamain 表单不能直接用你说的方法来做.

<块引用>

软件包 Microsoft.Toolkit.Uwp.UI.Controls 5.0.0 与 netstandard2.0 >>(.NETStandard,Version=v2.0) 不兼容.

但是,将此 NuGet 包添加到 UWP,您可以尝试使用自定义

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.

解决方案

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.

这篇关于Xamarin.Forms:独立于平台的应用程序菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆