InputBinding 클래스

정의

InputGesture와 명령 간의 바인딩을 나타냅니다. 명령은 RoutedCommand일 수 있습니다.

public ref class InputBinding : System::Windows::DependencyObject, System::Windows::Input::ICommandSource
public ref class InputBinding : System::Windows::Freezable, System::Windows::Input::ICommandSource
public class InputBinding : System.Windows.DependencyObject, System.Windows.Input.ICommandSource
public class InputBinding : System.Windows.Freezable, System.Windows.Input.ICommandSource
type InputBinding = class
    inherit DependencyObject
    interface ICommandSource
type InputBinding = class
    inherit Freezable
    interface ICommandSource
Public Class InputBinding
Inherits DependencyObject
Implements ICommandSource
Public Class InputBinding
Inherits Freezable
Implements ICommandSource
상속
상속
파생
구현

예제

다음 예제에서는 사용 하는 방법에 설명 합니다 KeyBinding 에 바인딩을 KeyGestureOpen 명령에 합니다. 키 제스처가 수행되면 Open 명령이 호출됩니다.

<Window.InputBindings>
  <KeyBinding Key="B"
              Modifiers="Control" 
              Command="ApplicationCommands.Open" />
</Window.InputBindings>

다음 예제에서는 개체에 사용자 지정 명령을 바인딩하는 InputBinding 방법을 보여 줍니다. 이 예제에서는 사용자가 다음 작업 중 하나를 수행 하 여 배경색을 변경할 수 있도록 하는 애플리케이션을 만듭니다.

  • 단추를 클릭합니다.

  • Ctrl+C를 누릅니다.

  • (외부)를 StackPanel 마우스 오른쪽 단추로 ListBox클릭합니다.

첫 번째 예제에서는 라는 SimpleDelegateCommand클래스를 만듭니다. 이 클래스는 명령을 만드는 개체가 명령을 실행할 때 발생하는 작업을 정의할 수 있도록 대리자를 허용합니다. SimpleDelegateCommand 또한 명령을 호출하는 키 및 마우스 입력을 지정하는 속성을 정의합니다. GestureKey 키보드 입력을 지정하고 GestureModifier 마우스 입력 MouseGesture 을 지정합니다.

 // Create a class that implements ICommand and accepts a delegate.
public class SimpleDelegateCommand : ICommand
{
    // Specify the keys and mouse actions that invoke the command. 
    public Key GestureKey { get; set; }
    public ModifierKeys GestureModifier { get; set; }
    public MouseAction MouseGesture { get; set; }

    Action<object> _executeDelegate;

    public SimpleDelegateCommand(Action<object> executeDelegate)
    {
        _executeDelegate = executeDelegate;
    }

    public void Execute(object parameter)
    {
        _executeDelegate(parameter);
    }

    public bool CanExecute(object parameter) { return true; }
    public event EventHandler CanExecuteChanged;
}
' Create a class that implements ICommand and accepts a delegate. 
Public Class SimpleDelegateCommand
    Implements ICommand

    ' Specify the keys and mouse actions that invoke the command. 
    Private _GestureKey As Key
    Private _GestureModifier As ModifierKeys
    Private _MouseGesture As MouseAction

    Public Property GestureKey() As Key
        Get
            Return _GestureKey
        End Get
        Set(ByVal value As Key)
            _GestureKey = value
        End Set
    End Property

    Public Property GestureModifier() As ModifierKeys
        Get
            Return _GestureModifier
        End Get
        Set(ByVal value As ModifierKeys)
            _GestureModifier = value
        End Set
    End Property

    Public Property MouseGesture() As MouseAction
        Get
            Return _MouseGesture
        End Get
        Set(ByVal value As MouseAction)
            _MouseGesture = value
        End Set
    End Property

    Private _executeDelegate As Action(Of Object)

    Public Sub New(ByVal executeDelegate As Action(Of Object))
        _executeDelegate = executeDelegate
    End Sub

    Public Sub Execute(ByVal parameter As Object) _
        Implements ICommand.Execute

        _executeDelegate(parameter)
    End Sub

    Public Function CanExecute(ByVal parameter As Object) As Boolean _
        Implements ICommand.CanExecute

        Return True
    End Function

    Public Event CanExecuteChanged As EventHandler _
        Implements ICommand.CanExecuteChanged
End Class

다음 예제에서는 을 만들고 초기화합니다ColorChangeCommandSimpleDelegateCommand. 이 예제에서는 명령이 호출될 때 실행되는 메서드를 정의하고 , GestureModifierMouseGesture 속성을 설정합니다GestureKey. 애플리케이션 호출을 InitializeCommand 의 생성자와 같이 프로그램을 시작할 때 메서드를 Window입니다.

public SimpleDelegateCommand ChangeColorCommand
{
    get { return changeColorCommand; }
}

private SimpleDelegateCommand changeColorCommand;

private void InitializeCommand()
{
    originalColor = this.Background;

    changeColorCommand = new SimpleDelegateCommand(x => this.ChangeColor(x));

    DataContext = this;
    changeColorCommand.GestureKey = Key.C;
    changeColorCommand.GestureModifier = ModifierKeys.Control;
    ChangeColorCommand.MouseGesture = MouseAction.RightClick;
}

private Brush originalColor, alternateColor;

// Switch the Background color between
// the original and selected color.
private void ChangeColor(object colorString)
{
    if (colorString == null)
    {
        return;
    }

    Color newColor = 
        (Color)ColorConverter.ConvertFromString((String)colorString);
    
    alternateColor = new SolidColorBrush(newColor);

    if (this.Background == originalColor)
    {
        this.Background = alternateColor;
    }
    else
    {
        this.Background = originalColor;
    }
}
Public ReadOnly Property ChangeColorCommand() As SimpleDelegateCommand
    Get
        Return _changeColorCommand
    End Get
End Property

Private _changeColorCommand As SimpleDelegateCommand
Private originalColor As Brush, alternateColor As Brush

Private Sub InitializeCommand()
    originalColor = Me.Background

    _changeColorCommand = New SimpleDelegateCommand(Function(x) Me.ChangeColor(x))

    DataContext = Me
    _changeColorCommand.GestureKey = Key.C
    _changeColorCommand.GestureModifier = ModifierKeys.Control
    _changeColorCommand.MouseGesture = MouseAction.RightClick
End Sub

' Switch the Background color between 
' the original and selected color. 
Private Function ChangeColor(ByVal colorString As Object) As Integer

    If colorString Is Nothing Then
        Return 0
    End If

    Dim newColor As Color = DirectCast(ColorConverter.ConvertFromString(DirectCast(colorString, [String])), Color)

    alternateColor = New SolidColorBrush(newColor)

    If Brush.Equals(Me.Background, originalColor) Then
        Me.Background = alternateColor
    Else
        Me.Background = originalColor
    End If

    Return 0
End Function

마지막으로 다음 예제에서는 사용자 인터페이스를 만듭니다. 이 예제에서는 및 KeyBindingMouseBinding 를 포함하는 에 StackPanelListBoxButton 추가합니다. 사용자가 에서 ListBox항목을 선택하면 배경색을 선택한 색으로 변경할 수 있습니다. 각 경우에 속성은 CommandParameter 에서 ListBox선택한 항목에 바인딩되고 Command 속성은 에 바인딩됩니다 ColorChangeCommand. KeyBinding.Key, KeyBinding.ModifiersMouseBinding.MouseAction 속성은 클래스의 해당 속성에 SimpleDelegateCommand 바인딩됩니다.

<StackPanel Background="Transparent">
  <StackPanel.InputBindings>
    
    <KeyBinding Command="{Binding ChangeColorCommand}"
                CommandParameter="{Binding ElementName=colorPicker, Path=SelectedItem}"
                Key="{Binding ChangeColorCommand.GestureKey}"
                Modifiers="{Binding ChangeColorCommand.GestureModifier}"/>

    <MouseBinding Command="{Binding ChangeColorCommand}"
                  CommandParameter="{Binding ElementName=colorPicker, Path=SelectedItem}"
                  MouseAction="{Binding ChangeColorCommand.MouseGesture}"/>
  
  </StackPanel.InputBindings>
  
  <Button Content="Change Color" 
          Command="{Binding ChangeColorCommand}" 
          CommandParameter="{Binding ElementName=colorPicker, Path=SelectedItem}">
  </Button>

  <ListBox Name="colorPicker"
           Background="Transparent"
           xmlns:sys="clr-namespace:System;assembly=mscorlib">
    <sys:String>Red</sys:String>
    <sys:String>Green</sys:String>
    <sys:String>Blue</sys:String>
    <sys:String>Yellow</sys:String>
    <sys:String>Orange</sys:String>
    <sys:String>Purple</sys:String>
  </ListBox>
</StackPanel>

설명

를 만들어 사용자 입력이 명령을 호출하는 것을 지정할 수 있습니다 InputBinding. 사용자가 지정된 입력 ICommand 을 수행하면 속성으로 설정된 가 Command 실행됩니다.

에서 , CommandParameterCommandTarget 속성에 바인딩을 만들어 Command개체에 정의된 명령을 호출할 수 InputBinding 있습니다. 이렇게 하면 사용자 지정 명령을 정의하고 사용자 입력과 연결할 수 있습니다. 자세한 내용은 예제 섹션의 두 번째 예제를 참조하세요.

InputBinding 에 등록하여 RegisterClassInputBindingCommandManager특정 개체 또는 클래스 수준에서 를 정의할 수 있습니다.

InputBinding 클래스 자체는 공용 매개 변수 없는 생성자를 노출하지 않기 때문에 XAML 사용을 지원하지 않습니다(매개 변수가 없는 생성자는 있지만 보호됨). 그러나 파생 클래스는 공용 생성자를 노출할 수 있으므로 XAML 사용량으로 에서 상속되는 파생 클래스의 InputBinding 속성을 설정할 수 있습니다. XAML에서 인스턴스화할 수 있고 XAML에서 속성을 설정할 수 있는 두 개의 기존 InputBinding파생 클래스는 및 MouseBinding입니다KeyBinding. XAML에서 설정되고 값이 속성이므로 하나 이상의 InputBinding 개체를 사용하는 WPF 프로그래밍의 UIElement.InputBindings 일반적인 속성입니다.

XAML 개체 요소 사용

<inputBindingDerivedClass.../>

XAML 값

inputBindingDerivedClass
또는 MouseBinding와 같은 KeyBinding 개체 요소 구문을 지원하는 의 InputBinding 파생 클래스입니다. 설명 부분을 참조하세요.

생성자

InputBinding()

InputBinding에서 파생된 클래스의 기본 초기화를 제공합니다.

InputBinding(ICommand, InputGesture)

지정한 명령과 입력 제스처를 사용하여 InputBinding 클래스의 새 인스턴스를 초기화합니다.

필드

CommandParameterProperty

CommandParameter 종속성 속성을 나타냅니다.

CommandProperty

Command 종속성 속성을 나타냅니다.

CommandTargetProperty

CommandTarget 종속성 속성을 나타냅니다.

속성

CanFreeze

개체를 수정 불가능으로 설정할 수 있는지 여부를 나타내는 값을 가져옵니다.

(다음에서 상속됨 Freezable)
Command

이 입력 바인딩과 연결된 ICommand를 가져오거나 설정합니다.

CommandParameter

특정 명령에 대한 명령별 데이터를 가져오거나 설정합니다.

CommandTarget

명령의 대상 요소를 가져오거나 설정합니다.

DependencyObjectType

DependencyObjectType 이 instance CLR 형식을 래핑하는 을 가져옵니다.

(다음에서 상속됨 DependencyObject)
Dispatcher

Dispatcher와 연결된 DispatcherObject를 가져옵니다.

(다음에서 상속됨 DispatcherObject)
Gesture

이 입력 바인딩과 연결된 InputGesture를 가져오거나 설정합니다.

IsFrozen

개체가 현재 수정 가능한지 여부를 나타내는 값을 가져옵니다.

(다음에서 상속됨 Freezable)
IsSealed

이 인스턴스가 현재 봉인되어 있는지(읽기 전용인지) 여부를 나타내는 값을 가져옵니다.

(다음에서 상속됨 DependencyObject)

메서드

CheckAccess()

호출 스레드가 이 DispatcherObject에 액세스할 수 있는지 여부를 확인합니다.

(다음에서 상속됨 DispatcherObject)
ClearValue(DependencyProperty)

속성의 로컬 값을 지웁니다. 지울 속성이 DependencyProperty 식별자에서 지정됩니다.

(다음에서 상속됨 DependencyObject)
ClearValue(DependencyPropertyKey)

읽기 전용 속성의 로컬 값을 지웁니다. 선언할 속성이 DependencyPropertyKey에서 지정됩니다.

(다음에서 상속됨 DependencyObject)
Clone()

개체 값의 전체 복사본을 만들어 Freezable의 수정 가능한 복제본을 만듭니다. 개체의 종속성 속성을 복사하는 경우 이 메서드는 더 이상 확인되지 않을 수도 있는 식을 복사하지만 애니메이션 또는 해당 현재 값은 복사하지 않습니다.

(다음에서 상속됨 Freezable)
CloneCore(Freezable)

지정된 개체의 속성에 대한 애니메이션이 적용되지 않은 기준 값을 복사합니다.

CloneCurrentValue()

현재 값을 사용하여 Freezable의 수정 가능한 복제본(전체 복사본)을 만듭니다.

(다음에서 상속됨 Freezable)
CloneCurrentValueCore(Freezable)

지정된 개체의 속성에 대한 현재 값을 복사합니다.

CoerceValue(DependencyProperty)

지정된 종속성 속성의 값을 강제 변환합니다. 호출하는 DependencyObject에 있으므로 이 작업은 종속성 속성의 속성 메타데이터에 지정된 CoerceValueCallback 함수를 호출하여 수행합니다.

(다음에서 상속됨 DependencyObject)
CreateInstance()

Freezable 클래스의 새 인스턴스를 초기화합니다.

(다음에서 상속됨 Freezable)
CreateInstanceCore()

InputBinding의 인스턴스를 만듭니다.

Equals(Object)

제공된 DependencyObject가 현재 DependencyObject에 해당하는지 여부를 확인합니다.

(다음에서 상속됨 DependencyObject)
Freeze()

현재 개체를 수정할 수 없게 설정하고 해당 IsFrozen 속성을 true로 설정합니다.

(다음에서 상속됨 Freezable)
FreezeCore(Boolean)

Freezable을 수정할 수 없게 만들거나, 수정할 수 없게 만들 수 있는지 테스트합니다.

(다음에서 상속됨 Freezable)
GetAsFrozen()

애니메이션이 적용되지 않은 기준 속성 값을 사용하여 Freezable의 고정된 복사본을 만듭니다. 복사본이 고정되므로 고정된 하위 개체는 모두 참조를 통해 복사됩니다.

(다음에서 상속됨 Freezable)
GetAsFrozenCore(Freezable)

애니메이션이 적용되지 않은 기준 속성 값을 사용하여 인스턴스를 지정된 Freezable의 고정된 복제본으로 만듭니다.

GetCurrentValueAsFrozen()

현재 속성 값을 사용하여 Freezable의 고정된 복사본을 만듭니다. 복사본이 고정되므로 고정된 하위 개체는 모두 참조를 통해 복사됩니다.

(다음에서 상속됨 Freezable)
GetCurrentValueAsFrozenCore(Freezable)

현재 인스턴스를 지정된 Freezable의 고정 클론으로 만듭니다. 개체에 애니메이션 효과를 준 종속성 속성이 있는 경우 애니메이션 효과를 준 현재 값이 복사됩니다.

GetHashCode()

DependencyObject의 해시 코드를 가져옵니다.

(다음에서 상속됨 DependencyObject)
GetLocalValueEnumerator()

DependencyObject에 대해 로컬로 값을 설정한 종속성 속성을 확인하기 위한 특수 열거자를 만듭니다.

(다음에서 상속됨 DependencyObject)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
GetValue(DependencyProperty)

DependencyObject의 인스턴스에서 종속성 속성의 현재 유효 값을 반환합니다.

(다음에서 상속됨 DependencyObject)
InvalidateProperty(DependencyProperty)

지정된 종속성 속성의 유효 값을 다시 계산합니다.

(다음에서 상속됨 DependencyObject)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
OnChanged()

현재 Freezable 개체가 수정될 때 호출됩니다.

(다음에서 상속됨 Freezable)
OnFreezablePropertyChanged(DependencyObject, DependencyObject)

방금 설정된 DependencyObjectType 데이터 멤버에 대한 적절한 컨텍스트 포인터를 설정합니다.

(다음에서 상속됨 Freezable)
OnFreezablePropertyChanged(DependencyObject, DependencyObject, DependencyProperty)

이 멤버는 WPF(Windows Presentation Foundation) 인프라를 지원하며 코드에서 직접 사용할 수 없습니다.

(다음에서 상속됨 Freezable)
OnPropertyChanged(DependencyPropertyChangedEventArgs)

DependencyObject에서 종속성 속성의 유효 값이 업데이트될 때마다 호출됩니다. 변경된 특정 종속성 속성이 이벤트 데이터에서 보고됩니다.

(다음에서 상속됨 DependencyObject)
OnPropertyChanged(DependencyPropertyChangedEventArgs)

OnPropertyChanged(DependencyPropertyChangedEventArgs)DependencyObject 구현을 재정의하여 Freezable 형식의 변화하는 종속성 속성에 대한 응답으로 Changed 처리기도 호출합니다.

(다음에서 상속됨 Freezable)
ReadLocalValue(DependencyProperty)

종속성 속성의 로컬 값을 반환합니다(있는 경우).

(다음에서 상속됨 DependencyObject)
ReadPreamble()

유효한 스레드에서 Freezable에 액세스하고 있는지 확인합니다. Freezable 상속자는 종속성 속성이 아닌 데이터 멤버를 읽는 API의 시작 부분에서 이 메서드를 호출해야 합니다.

(다음에서 상속됨 Freezable)
SetCurrentValue(DependencyProperty, Object)

해당 값 소스를 변경하지 않고 종속성 속성의 값을 설정합니다.

(다음에서 상속됨 DependencyObject)
SetValue(DependencyProperty, Object)

지정된 종속성 속성 식별자를 가진 종속성 속성의 로컬 값을 설정합니다.

(다음에서 상속됨 DependencyObject)
SetValue(DependencyPropertyKey, Object)

종속성 속성의 DependencyPropertyKey 식별자에 의해 지정된 읽기 전용 종속성 속성의 로컬 값을 설정합니다.

(다음에서 상속됨 DependencyObject)
ShouldSerializeProperty(DependencyProperty)

serialization 프로세스에서 지정된 종속성 속성의 값을 직렬화해야 하는지 여부를 나타내는 값을 반환합니다.

(다음에서 상속됨 DependencyObject)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)
VerifyAccess()

호출 스레드에서 이 DispatcherObject에 액세스할 수 있는지 확인합니다.

(다음에서 상속됨 DispatcherObject)
WritePostscript()

Changed 에 대한 Freezable 이벤트를 발생시키고 해당 OnChanged() 메서드를 호출합니다. Freezable에서 파생된 클래스는 종속성 속성으로 저장되지 않은 클래스 멤버를 수정하는 모든 API의 끝에서 이 메서드를 호출해야 합니다.

(다음에서 상속됨 Freezable)
WritePreamble()

Freezable이 고정되어 있지 않고 유효한 스레드 컨텍스트에서 액세스되고 있는지 확인합니다. Freezable 상속자는 종속성 속성이 아닌 데이터 멤버에 쓰는 API의 시작 부분에서 이 메서드를 호출해야 합니다.

(다음에서 상속됨 Freezable)

이벤트

Changed

Freezable 또는 여기에 들어 있는 개체가 수정될 때 발생합니다.

(다음에서 상속됨 Freezable)

적용 대상

추가 정보