2009-07-29 19 views

Antwort

2

Hier können Sie ersetzen ApplicationCommands.Copy mit dem Befehl, den Sie suchen .

foreach (KeyBinding binding in InputBindings) 
{ 
    if (binding.Command == ApplicationCommands.Copy) 
    { 
     MessageBox.Show(binding.Modifiers.ToString() + " + " + binding.Key.ToString()); 
    } 
} 
-2

Verwendung KeyBinding - http://msdn.microsoft.com/en-us/library/ms752308.aspx

<Window.InputBindings> 
    <KeyBinding Key="C" 
      Modifiers="Control" 
      Command="ApplicationCommands.Copy" /> 
</Window.InputBindings> 
+1

Nein, fragt er, wie erhalten Sie die Tastenkombination, nicht, wie Sie die KeyBinding hinzufügen. – Charlie

1

Leider denke ich, das die eigentliche Antwort auf Ihre Frage ist:

Button b = new Button(); 

b.Command = ApplicationCommands.Copy; 

List<string> gestures = new List<string>(); 

if (b.Command is RoutedCommand) 
{ 
    RoutedCommand command = (b.Command as RoutedCommand); 

    foreach (InputGesture gesture in command.InputGestures) 
    { 
     if (gesture is KeyGesture) 
     gestures.Add((gesture as KeyGesture).DisplayString); 
    } 
} 

Wenn der Grund, warum Sie bekommen wollen, ist es in der angezeigt werden Knopfinhalt, können Sie immer dies tun:

<Button Command="ApplicationCommands.New" Content="{Binding RelativeSource={RelativeSource Self}, Path=Command.Text}"></Button> 

Das wird die Schaltfläche "New" haben.

Verwandte Themen