InputBinding 클래스
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
명령과 명령 간의 바인딩을 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
- 상속
- 상속
- 파생
- 구현
예제
다음 예제에서는 명령에 바인딩 KeyGestureOpen 하는 KeyBinding 데 사용하는 방법을 보여줍니다. 키 제스처가 수행되면 Open 명령이 호출됩니다.
<Window.InputBindings>
<KeyBinding Key="B"
Modifiers="Control"
Command="ApplicationCommands.Open" />
</Window.InputBindings>
다음 예제에서는 개체에 사용자 지정 명령을 바인딩하는 InputBinding 방법을 보여 줍니다. 다음 예제에서는 다음 작업 중 하나를 수행하여 사용자가 배경색을 변경할 수 있도록 하는 애플리케이션을 만듭니다.
단추를 클릭합니다.
Ctrl+C를 누릅니다.
(외부)를 마우스 오른쪽 단추로 StackPanelListBox클릭합니다.
첫 번째 예제에서는 라는 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. 또한 명령이 호출될 때 실행되는 메서드를 정의하고 , GestureModifier및 MouseGesture 속성을 설정합니다GestureKey. 애플리케이션은 프로그램의 생성자와 같이 프로그램이 시작될 때 메서드를 Window호출 InitializeCommand 합니다.
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
마지막으로 다음 예제에서는 사용자 인터페이스를 만듭니다. 이 예제에서는 a KeyBinding 와 a MouseBindingStackPanel 를 포함하는 a와 ListBoxa Button 를 추가합니다. 사용자가 해당 항목에서 ListBox항목을 선택하면 배경색을 선택한 색으로 변경할 수 있습니다. 각 경우 CommandParameter 에서 속성은 선택한 항목에 ListBox바인딩되고 Command 속성은 .에 바인딩 ColorChangeCommand됩니다.
KeyBinding.Key, KeyBinding.Modifiers및 MouseBinding.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 설정된 입력이 실행됩니다.
및 속성에 InputBinding 바인딩 CommandCommandParameterCommandTarget 을 만들어 개체에 정의된 명령을 호출할 수 있습니다. 이렇게 하면 사용자 지정 명령을 정의하고 사용자 입력과 연결할 수 있습니다. 자세한 내용은 예제 섹션의 두 번째 예제를 참조하세요.
에 InputBinding 등록 RegisterClassInputBindingCommandManager하여 특정 개체 또는 클래스 수준에서 정의할 수 있습니다.
InputBinding 클래스 자체는 공용 매개 변수가 없는 생성자를 노출하지 않으므로 XAML 사용을 지원하지 않습니다(매개 변수가 없는 생성자는 있지만 보호됨). 그러나 파생 클래스는 공용 생성자를 노출할 수 있으므로 XAML 사용으로 상속된 파생 클래스에서 InputBinding 속성을 설정할 수 있습니다. XAML에서 인스턴스화할 수 있고 XAML에서 속성을 설정할 수 있는 두 개의 기존 InputBinding파생 클래스는 다음과 MouseBinding같습니다KeyBinding. XAML에서 설정되고 값이 속성이므로 하나 이상의 InputBinding 개체를 사용하는 WPF 프로그래밍의 UIElement.InputBindings 일반적인 속성입니다.
XAML 개체 요소 사용
< inputBindingDerivedClass.../>
XAML 값
inputBindingDerivedClass개체 요소 구문(예: KeyBinding 또는 MouseBinding.)을 지원하는 파생 클래스 InputBinding 입니다. 비고 섹션을 참고하십시오.
생성자
| Name | Description |
|---|---|
| InputBinding() |
에서 파생된 InputBinding클래스에 대한 기본 초기화를 제공합니다. |
| InputBinding(ICommand, InputGesture) |
지정된 명령 및 입력 제스처를 InputBinding 사용하여 클래스의 새 인스턴스를 초기화합니다. |
필드
| Name | Description |
|---|---|
| CommandParameterProperty |
CommandParameter 종속성 속성을 식별합니다. |
| CommandProperty |
Command 종속성 속성을 식별합니다. |
| CommandTargetProperty |
CommandTarget 종속성 속성을 식별합니다. |
속성
| Name | Description |
|---|---|
| CanFreeze |
개체를 수정할 수 없게 만들 수 있는지 여부를 나타내는 값을 가져옵니다. (다음에서 상속됨 Freezable) |
| Command |
이 입력 바인딩과 연결된 값을 가져오거나 설정합니다 ICommand . |
| CommandParameter |
특정 명령에 대한 명령별 데이터를 가져오거나 설정합니다. |
| CommandTarget |
명령의 대상 요소를 가져오거나 설정합니다. |
| DependencyObjectType |
이 인스턴스의 DependencyObjectType CLR 형식을 래핑하는 값을 가져옵니다. (다음에서 상속됨 DependencyObject) |
| Dispatcher |
연결된 이 값을 DispatcherDispatcherObject 가져옵니다. (다음에서 상속됨 DispatcherObject) |
| Gesture |
이 입력 바인딩과 연결된 값을 가져오거나 설정합니다 InputGesture . |
| IsFrozen |
개체를 현재 수정할 수 있는지 여부를 나타내는 값을 가져옵니다. (다음에서 상속됨 Freezable) |
| IsSealed |
이 인스턴스가 현재 봉인되어 있는지 여부를 나타내는 값을 가져옵니다(읽기 전용). (다음에서 상속됨 DependencyObject) |
메서드
| Name | Description |
|---|---|
| CheckAccess() |
호출 스레드에 이 DispatcherObject액세스 권한이 있는지 여부를 확인합니다. (다음에서 상속됨 DispatcherObject) |
| ClearValue(DependencyProperty) |
속성의 로컬 값을 지웁니다. 지울 속성은 식별자에 의해 DependencyProperty 지정됩니다. (다음에서 상속됨 DependencyObject) |
| ClearValue(DependencyPropertyKey) |
읽기 전용 속성의 로컬 값을 지웁니다. 지울 속성은 .에 DependencyPropertyKey의해 지정됩니다. (다음에서 상속됨 DependencyObject) |
| Clone() |
개체 값의 전체 복사본을 Freezable만드는 수정 가능한 복제본을 만듭니다. 개체의 종속성 속성을 복사할 때 이 메서드는 더 이상 확인되지 않을 수 있는 식을 복사하지만 애니메이션이나 현재 값은 복사하지 않습니다. (다음에서 상속됨 Freezable) |
| CloneCore(Freezable) |
지정된 개체의 속성에 대한 기본(애니메이션이 아닌) 값을 복사합니다. |
| CloneCurrentValue() |
현재 값을 사용하는 수정 가능한 클론(전체 복사본) Freezable 을 만듭니다. (다음에서 상속됨 Freezable) |
| CloneCurrentValueCore(Freezable) |
지정된 개체의 속성에 대한 현재 값을 복사합니다. |
| CoerceValue(DependencyProperty) |
지정된 종속성 속성의 값을 강제 변환합니다. 이 작업은 호출 CoerceValueCallback시 종속성 속성에 대한 속성 메타데이터에 지정된 함수 DependencyObject 를 호출하여 수행됩니다. (다음에서 상속됨 DependencyObject) |
| CreateInstance() |
Freezable 클래스의 새 인스턴스를 초기화합니다. (다음에서 상속됨 Freezable) |
| CreateInstanceCore() |
의 인스턴스를 InputBinding만듭니다. |
| Equals(Object) |
제공된 DependencyObject 항목이 현재 DependencyObject와 같은지 여부를 확인합니다. (다음에서 상속됨 DependencyObject) |
| Freeze() |
현재 개체를 수정할 수 없게 만들고 해당 IsFrozen 속성을 .로 |
| FreezeCore(Boolean) |
개체를 Freezable 수정할 수 없게 만들거나 수정할 수 없는 개체를 만들 수 있는지 테스트합니다. (다음에서 상속됨 Freezable) |
| GetAsFrozen() |
기본(애니메이션이 아닌) 속성 값을 사용하여 고정된 복사본 Freezable을 만듭니다. 복사본이 고정되어 있으므로 고정된 하위 개체는 참조로 복사됩니다. (다음에서 상속됨 Freezable) |
| GetAsFrozenCore(Freezable) |
기본(애니메이션이 적용되지 않은) 속성 값을 사용하여 인스턴스를 지정된 Freezable 고정 클론으로 만듭니다. |
| GetCurrentValueAsFrozen() |
using 현재 속성 값의 고정 복사본을 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, DependencyProperty) |
이 멤버는 WPF(Windows Presentation Foundation) 인프라를 지원하며 코드에서 직접 사용할 수 없습니다. (다음에서 상속됨 Freezable) |
| OnFreezablePropertyChanged(DependencyObject, DependencyObject) |
방금 설정된 데이터 멤버에 대해 적절한 컨텍스트 포인터가 DependencyObjectType 설정되었는지 확인합니다. (다음에서 상속됨 Freezable) |
| OnPropertyChanged(DependencyPropertyChangedEventArgs) |
이에 대한 종속성 속성의 유효 값이 DependencyObject 업데이트될 때마다 호출됩니다. 변경된 특정 종속성 속성은 이벤트 데이터에 보고됩니다. (다음에서 상속됨 DependencyObject) |
| OnPropertyChanged(DependencyPropertyChangedEventArgs) |
형식Freezable의 OnPropertyChanged(DependencyPropertyChangedEventArgs) 변경된 종속성 속성에 대한 응답으로 처리 Changed 기를 호출하는 구현도 재정 DependencyObject 의합니다. (다음에서 상속됨 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 프로세스가 제공된 종속성 속성의 값을 serialize해야 하는지 여부를 나타내는 값을 반환합니다. (다음에서 상속됨 DependencyObject) |
| ToString() |
현재 개체를 나타내는 문자열을 반환합니다. (다음에서 상속됨 Object) |
| VerifyAccess() |
호출 스레드가 이에 DispatcherObject액세스할 수 있도록 합니다. (다음에서 상속됨 DispatcherObject) |
| WritePostscript() |
에 Changed 대한 Freezable 이벤트를 발생시키고 해당 OnChanged() 메서드를 호출합니다. 파생 Freezable 되는 클래스는 종속성 속성으로 저장되지 않은 클래스 멤버를 수정하는 API의 끝에 이 메서드를 호출해야 합니다. (다음에서 상속됨 Freezable) |
| WritePreamble() |
Freezable 고정되지 않고 유효한 스레딩 컨텍스트에서 액세스되고 있는지 확인합니다. Freezable 상속자는 종속성 속성이 아닌 데이터 멤버에 쓰는 API의 시작 부분에서 이 메서드를 호출해야 합니다. (다음에서 상속됨 Freezable) |
이벤트
| Name | Description |
|---|---|
| Changed |
포함된 개체 또는 개체를 수정할 때 Freezable 발생합니다. (다음에서 상속됨 Freezable) |