Defining MenuItem Shortcuts

后端 未结 6 610
北恋
北恋 2020-11-27 14:02

I need a simple way to set a shortcut for menu items.

But this don´t work with shortcut, just with click:


    <         


        
6条回答
  •  时光取名叫无心
    2020-11-27 14:40

    This work for me

    
        
    
    

    Code behind:

    private void ContextMenu_PreviewKeyUp(object sender, KeyEventArgs e)
    {
        ContextMenu contextMenu = sender as ContextMenu;
        if (e.Key == Key.D)
        {
            //DELETE ID
    
        }
        contextMenu.IsOpen = false;
    }
    

提交回复
热议问题