CommandBindingCollection.Add(CommandBinding) Metodo

Definizione

Aggiunge l'oggetto specificato CommandBinding all'oggetto 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
Public Function Add (commandBinding As CommandBinding) As Integer

Parametri

commandBinding
CommandBinding

Associazione da aggiungere alla raccolta.

Valori restituiti

0, se l'operazione ha avuto esito positivo (si noti che questo non è l'indice dell'elemento aggiunto).

Eccezioni

commandBinding è Null.

Esempio

Nell'esempio seguente viene creato un CommandBinding oggetto e viene aggiunto all'oggetto CommandBindingCollection di un oggetto 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)

Si applica a

Vedi anche