{"id":165,"date":"2017-02-11T14:32:25","date_gmt":"2017-02-11T14:32:25","guid":{"rendered":"http:\/\/windows.emacslisp.com\/?p=165"},"modified":"2017-02-11T14:33:13","modified_gmt":"2017-02-11T14:33:13","slug":"wpf-add-key-short-cut-for-windows","status":"publish","type":"post","link":"http:\/\/windows.emacslisp.com\/index.php\/2017\/02\/11\/wpf-add-key-short-cut-for-windows\/","title":{"rendered":"WPF &#8211; add key short cut for windows"},"content":{"rendered":"<p>there is two ways to add wpf key short cut.<\/p>\n<pre lang=\"csharp\" line=\"1\">\r\n        this.KeyUp += MainWindow_KeyUp;\r\n\r\n        private void MainWindow_KeyUp(object sender, KeyEventArgs e)\r\n        {\r\n            if(e.Key == Key.D1)\r\n            {\r\n                MessageBox.Show(\"1 is press\");\r\n            }\r\n        }\r\n<\/pre>\n<p>but for the most normal way to do is to wpf resource.<\/p>\n<pre lang=\"xml\" line=\"1\" escaped=\"true\"> \r\n\r\n    <Window.Resources>\r\n        <RoutedUICommand x:Key=\"ClickCommand\" Text=\"Text\" \/>\r\n    <\/Window.Resources>\r\n    <Window.InputBindings>\r\n        <KeyBinding Command=\"{Binding Path=button_Click}\" \r\n                Key=\"O\" \r\n                Modifiers=\"Control\"\/>\r\n        <KeyBinding Key=\"C\" Command=\"{StaticResource ClickCommand}\" \/>\r\n    <\/Window.InputBindings>\r\n\r\n    <Window.CommandBindings>\r\n        <CommandBinding Command=\"{StaticResource ClickCommand}\" \r\n                    Executed=\"button_Click\" \/>\r\n    <\/Window.CommandBindings>\r\n\r\n    <Grid>\r\n        <Button x:Name=\"button1\" Content=\"1\" HorizontalAlignment=\"Left\" Margin=\"101,140,0,0\" VerticalAlignment=\"Top\" Width=\"75\" Click=\"button1_Click\" Command=\"{StaticResource ClickCommand}\"\/>\r\n        <Button x:Name=\"button\" Content=\"2\" HorizontalAlignment=\"Left\" VerticalAlignment=\"Top\" Width=\"75\" Margin=\"181,140,0,0\" Click=\"button_Click\" Command=\"{StaticResource ClickCommand}\"\/>\r\n    <\/Grid>\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>WPF &#8211; two ways to add key short cut for windows and buttons <a href=\"http:\/\/windows.emacslisp.com\/index.php\/2017\/02\/11\/wpf-add-key-short-cut-for-windows\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"_links":{"self":[{"href":"http:\/\/windows.emacslisp.com\/index.php\/wp-json\/wp\/v2\/posts\/165"}],"collection":[{"href":"http:\/\/windows.emacslisp.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/windows.emacslisp.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/windows.emacslisp.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/windows.emacslisp.com\/index.php\/wp-json\/wp\/v2\/comments?post=165"}],"version-history":[{"count":2,"href":"http:\/\/windows.emacslisp.com\/index.php\/wp-json\/wp\/v2\/posts\/165\/revisions"}],"predecessor-version":[{"id":167,"href":"http:\/\/windows.emacslisp.com\/index.php\/wp-json\/wp\/v2\/posts\/165\/revisions\/167"}],"wp:attachment":[{"href":"http:\/\/windows.emacslisp.com\/index.php\/wp-json\/wp\/v2\/media?parent=165"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/windows.emacslisp.com\/index.php\/wp-json\/wp\/v2\/categories?post=165"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/windows.emacslisp.com\/index.php\/wp-json\/wp\/v2\/tags?post=165"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}