在UserControl頁面實現經過快捷鍵打開新建窗口html
其實,使用KeyDown事件也是能夠的
頁面代碼ide
<Window x:Class="WpfApp2.MainWindow" PreviewKeyDown="Window_PreviewKeyDown" ......>this
後置頁代碼.net
private void Window_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (this.ShowContent.Content is BaseUserControl control) control.ListenWindowKeyDown(e);
}htm
BaseUserControl繼承自UserControl,定義了虛方法,以便重寫blog
public virtual void ListenWindowKeyDown(KeyEventArgs e)
{
//若是須要使用事件,須要重寫,此處不作任何處理
}繼承
// 監聽窗口KeyDown事件
public override void ListenWindowKeyDown(KeyEventArgs e)
{
//DEMO
if (Keyboard.IsKeyDown(Key.LeftAlt) && Keyboard.IsKeyDown(Key.N)) { //TODO }
}事件
到此完成,具體的快捷鍵觸發就不寫了object
https://blog.csdn.net/BYH371256/article/details/89394198
WPFの三種方式實現快捷鍵List
https://www.cnblogs.com/lonelyxmas/p/9941791.html WPF UserControl響應PreviewKeyDown事件方法