CommandBindingCollection.Add(CommandBinding) 메서드

정의

지정된 CommandBinding를 이 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

매개 변수

commandBinding
CommandBinding

컬렉션에 추가할 바인딩입니다.The binding to add to the collection.

반환

작업이 완료되었으면 0입니다. 이 값은 추가된 항목의 인덱스가 아닙니다.0, if the operation was successful (note that this is not the index of the added item).

예외

commandBindingnull인 경우commandBinding is null.

예제

다음 예제에서는 CommandBinding 에 추가 합니다 CommandBindingCollectionWindow합니다.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)

적용 대상

추가 정보