InputBindingCollection.Add(InputBinding) Método

Definição

Adiciona o InputBinding especificado a este InputBindingCollection.

public:
 int Add(System::Windows::Input::InputBinding ^ inputBinding);
public int Add (System.Windows.Input.InputBinding inputBinding);
member this.Add : System.Windows.Input.InputBinding -> int
Public Function Add (inputBinding As InputBinding) As Integer

Parâmetros

inputBinding
InputBinding

A associação a adicionar à coleção.

Retornos

Sempre retorna 0. Isso se desvia da implementação de IList padrão para Add, que deve retornar o índice em que o novo item foi adicionado à coleção.

Exceções

inputBinding é null.

Exemplos

O exemplo a seguir cria um KeyGesture e o associa a um KeyBinding. O KeyBinding é adicionado ao InputBindingCollection em um Window.

<Window.InputBindings>
  <KeyBinding Key="B"
              Modifiers="Control" 
              Command="ApplicationCommands.Open" />
</Window.InputBindings>
KeyGesture OpenKeyGesture = new KeyGesture(
    Key.B,
    ModifierKeys.Control);

KeyBinding OpenCmdKeybinding = new KeyBinding(
    ApplicationCommands.Open,
    OpenKeyGesture);

this.InputBindings.Add(OpenCmdKeybinding);
Dim OpenKeyGesture As New KeyGesture(Key.B, ModifierKeys.Control)

Dim OpenCmdKeybinding As New KeyBinding(ApplicationCommands.Open, OpenKeyGesture)

Me.InputBindings.Add(OpenCmdKeybinding)

O exemplo XAML não usa Addliteralmente , mas Add é chamado implicitamente pelo suporte de processamento XAML para coleções. Para obter detalhes sobre XAML e coleções, consulte Visão geral de XAML (WPF).

Aplica-se a

Confira também