CommandBindingCollection.Add(CommandBinding) メソッド

定義

指定した CommandBinding をこの 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

パラメーター

commandBinding
CommandBinding

コレクションに追加するバインド。

返品

操作が成功した場合は 0 (追加された項目のインデックスではないことに注意してください)。

例外

commandBindingnull です

次の例では、CommandBindingを作成し、CommandBindingCollectionWindowに追加します。

<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)

適用対象

こちらもご覧ください