c# - Keyboard shortcut for wpf menu item -


i trying add keyboard shortcut menu item in xaml code using

<menuitem x:name="options" header="_options" inputgesturetext="ctrl+o" click="options_click"/> 

with ctrl+o

but not working - not calling click option.

are there solutions this?

inputgesturetext text. not bind key menuitem.

this property not associate input gesture menu item; adds text menu item. application must handle user's input carry out action

what can create routeduicommand in window assigned input gesture

public partial class mainwindow : window {     public static readonly routedcommand optionscommand = new routeduicommand("options", "optionscommand", typeof(mainwindow), new inputgesturecollection(new inputgesture[]         {             new keygesture(key.o, modifierkeys.control)         }));      //... } 

and in xaml bind command method set command against menuitem. in case both inputgesturetext , header pulled routeduicommand don't need set against menuitem

<window.commandbindings>     <commandbinding command="{x:static local:mainwindow.optionscommand}" executed="options_click"/> </window.commandbindings> <menu>     <!-- -->     <menuitem command="{x:static local:mainwindow.optionscommand}"/> </menu> 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -