更新时间:2023-12-02 23:40:10
您可以在主窗口中编写按键事件.
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>