按下ALT键时如何使WPF MenuBar可见? [英] How to make WPF MenuBar visibile when ALT-key is pressed?

查看:108
本文介绍了按下ALT键时如何使WPF MenuBar可见?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天,我在WPF用户界面上有了一些新的限制,这些限制应该消除MenuBar的永久可见性.

Today I got some new restrictions on my WPF user interface that should eliminate the permanent visibility of the MenuBar.

我想到模仿Windows Live Messenger的用户界面.仅当按ALT键时,该应用程序才会显示MenuBar.并在失去对MenuBar的焦点时再次将其隐藏.

I thought of imitating the user interface of Windows Live Messenger. That application displays the MenuBar only if the ALT-key is pressed. And hides it again when the focus on the MenuBar is lost.

目前我不知道如何在WPF中构建这样的东西……这可能吗?

Currently I don't have a clue how to build such a thing in WPF... is something like this possible?

谢谢.

推荐答案

您可以在主窗口中编写按键事件.

You can write a key down event on main window..

KeyDown="Window_KeyDown"

以及文件后面的代码中..

and in the code behind file..

 private void Window_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.LeftAlt || e.Key == Key.RightAlt)
            {
                myMenu.Visibility = Visibility.Visible;
            }
        }

如果您想通过MVVM或使用绑定来实现这一点...您可以使用输入键绑定

if you want to achive this with MVVM or using bindings... you can use input key bindings

 <Window.InputBindings>
        <KeyBinding Key="LeftAlt" Command="{Binding ShowMenuCommand}"/>
        <KeyBinding Key="RightAlt" Command="{Binding ShowMenuCommand}"/>
    </Window.InputBindings>

这篇关于按下ALT键时如何使WPF MenuBar可见?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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