如何使用XAML在菜单中使用“关闭"命令? [英] How to use 'Close' command in Menu using XAML?

查看:81
本文介绍了如何使用XAML在菜单中使用“关闭"命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我在菜单命令中有一个问题,尝试使用此XAML代码从窗口退出:

Hi guys

I have a bit problem in menu commands, that trying exit from window with this XAML code:

<Menu>
    <MenuItem Header="_File">
        <MenuItem Header="a" />
        <Separator />
        <MenuItem Header="E_xit" InputGestureText="Alt+F4" Command="ApplicationCommands.Close" />
    </MenuItem>
</Menu>


但是,在File菜单中单击时,Exit项被禁用,什么问题?可以不绑定到窗口吗?该怎么做?

感谢advacne:)


But when click in File menu, the Exit item is disabled, what problem? May it''s not bind to window? How to do this?

Thanks in advacne:)

推荐答案

您是否尝试过添加自己的close方法并调用该方法而不是发送命令?您是否尝试过删除InputGesture?我不知道答案,但是在我看来,有些试验和错误会帮助解决问题.
Have you tried adding your own close method and calling that instead of sending a command ? Have you tried removing the InputGesture ? I don''t know the answer, but it seems to me like some trial and error would help work it out.


我在XAML窗口中使用了此代码:
I used this code in window XAML:
<window.inputbindings>
    <keybinding command="NotACommand" modifiers="Alt" key="F4" />
    <keybinding command="Close" key="F2" />
</window.inputbindings>
<window.commandbindings>
    <commandbinding command="Close" executed="CommandBinding_Executed" />
</window.commandbindings>


菜单中的以下代码:


And this code in the menu:

<menu>
    <menuitem header="_File">
        <menuitem header="a" />
        <separator />
        <menuitem header="E_xit" inputgesturetext="F2" command="ApplicationCommands.Close" />
    </menuitem>
</menu>


终于解决了问题;)


Finally the problem is solved;)


这篇关于如何使用XAML在菜单中使用“关闭"命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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