2011-11-09 67 views
3

私はwpfアプリケーションを初めて使用しています。アプリケーションで作業しています。メニューを作成しました。ショートカットCtrl + O、Ctrl + Nなどのメニュー項目を機能させたいのですが私はそれを行う。詳細を私に与えてください。Wpfアプリケーションでショートカットキーを実装する

+0

http://blogs.windowsclient.net/vsdev/archive/2009/03/30/wpf-menu-how-to-implement-shortcut-keys.aspx – Kendrick

+0

@Anuあなたが取り組んでいるフレームワーク... .Net 4.0または.Net 3.5? – Ankesh

+0

私はVS2010で作業しています.4.0 – Anu

答えて

3

あなたはそれ以下のようにすることができます....

XAMLファイル内のコードで

<Window x:Class="FocusDemo.Window1" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:local="clr-namespace:FocusDemo" 
Title="Window1" Height="300" Width="300"> 

<Window.CommandBindings> 
    <CommandBinding 
     Command= 
     "{x:Static 
     local:Window1.CustomRoutedCommand}"      
     Executed="ExecutedCustomCommand" 
     CanExecute="CanExecuteCustomCommand" > 
    </CommandBinding> 
</Window.CommandBindings> 
<Window.InputBindings> 
    <KeyBinding 
     Command= 
     "{x:Static 
     local:Window1.CustomRoutedCommand}" 
     Key="S" 
     Modifiers="Control"/> 
</Window.InputBindings> 
<Grid> 
<!--Your Controls--> 
</Grid> 
</Window> 

ファイルの背後にある

/// <summary> 
/// Interaction logic for Window1.xaml 
/// </summary> 
public partial class Window1 : Window 
{ 
    public static RoutedCommand CustomRoutedCommand = new RoutedCommand();  
    public Window1() 
    {    
     InitializeComponent();  
    } 
    #region 
    public void ExecutedCustomCommand(object sender, ExecutedRoutedEventArgs e) 
    { 
     MessageBox.Show("Ctrl+S"); 
    } 


    public void CanExecuteCustomCommand(object sender, 
     CanExecuteRoutedEventArgs e) 
    { 
     e.CanExecute = true; 
    } 
    #endregion 

} 

出典:Click here

してください正しい場合は答えをマークすることを忘れないでください

0

質問に正確な答えはありませんが、私のような誰かがAlt + O、Alt + Nなどのメニュー項目(コマンドボタン)にキーボードショートカットを置く方法を探していた可能性があります。この場合、項目名にショートカット文字の前には、不要な文字(_)を入れることができます。

関連する問題