다음을 통해 공유


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)

적용 대상

추가 정보