CommandBindingCollection.Add(CommandBinding) Método

Definição

Adiciona o CommandBinding especificado a este CommandBindingCollection.Adds the specified CommandBinding to this CommandBindingCollection.

public:
 int Add(System::Windows::Input::CommandBinding ^ commandBinding);
public int Add (System.Windows.Input.CommandBinding commandBinding);
member this.Add : System.Windows.Input.CommandBinding -> int

Parâmetros

commandBinding
CommandBinding

A associação a adicionar à coleção.The binding to add to the collection.

Retornos

0, se a operação foi bem-sucedida (observe que isso não é o índice do item adicionado).0, if the operation was successful (note that this is not the index of the added item).

Exceções

commandBinding é nulo.commandBinding is null.

Exemplos

O exemplo a seguir cria CommandBinding um e o CommandBindingCollection adiciona ao de um Window.The following example creates a CommandBinding and adds it to the CommandBindingCollection of a Window.

<Window x:Class="SDKSamples.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:custom="clr-namespace:SDKSamples"
    Height="600" Width="800"
    >
  <Window.CommandBindings>
    <CommandBinding Command="{x:Static custom:Window1.CustomRoutedCommand}"
                    Executed="ExecutedCustomCommand"
                    CanExecute="CanExecuteCustomCommand" />
  </Window.CommandBindings>
CommandBinding customCommandBinding = new CommandBinding(
    CustomRoutedCommand, ExecutedCustomCommand, CanExecuteCustomCommand);

// attach CommandBinding to root window
this.CommandBindings.Add(customCommandBinding);
Dim customCommandBinding As New CommandBinding(CustomRoutedCommand, AddressOf ExecutedCustomCommand, AddressOf CanExecuteCustomCommand)

' attach CommandBinding to root window
Me.CommandBindings.Add(customCommandBinding)

Aplica-se a

Veja também