MouseBinding 类

定义

MouseGesture 绑定到 RoutedCommand(或另一个 ICommand 实现)。Binds a MouseGesture to a RoutedCommand (or another ICommand implementation).

public ref class MouseBinding : System::Windows::Input::InputBinding
public class MouseBinding : System.Windows.Input.InputBinding
type MouseBinding = class
    inherit InputBinding
Public Class MouseBinding
Inherits InputBinding
继承
继承

示例

下面的示例演示如何使用 MouseBindingMouseGesture 绑定到 RoutedCommandThe following example shows how to use a MouseBinding to bind a MouseGesture to a RoutedCommand.

<MouseBinding Gesture="Control+WheelClick"
              Command="ApplicationCommands.Open" />
MouseGesture OpenCmdMouseGesture = new MouseGesture();
OpenCmdMouseGesture.MouseAction = MouseAction.WheelClick;
OpenCmdMouseGesture.Modifiers = ModifierKeys.Control;

MouseBinding OpenCmdMouseBinding = new MouseBinding();
OpenCmdMouseBinding.Gesture = OpenCmdMouseGesture;
OpenCmdMouseBinding.Command = ApplicationCommands.Open;

this.InputBindings.Add(OpenCmdMouseBinding);
Dim OpenCmdMouseGesture As New MouseGesture()
OpenCmdMouseGesture.MouseAction = MouseAction.WheelClick
OpenCmdMouseGesture.Modifiers = ModifierKeys.Control

Dim OpenCmdMouseBinding As New MouseBinding()
OpenCmdMouseBinding.Gesture = OpenCmdMouseGesture
OpenCmdMouseBinding.Command = ApplicationCommands.Open

Me.InputBindings.Add(OpenCmdMouseBinding)

注解

MouseBindingMouseGestureICommand 实现相关联。A MouseBinding associates a MouseGesture with an ICommand implementation. RoutedCommandWPFWPF 命令系统的 ICommand 接口的主要实现。RoutedCommand is the primary implementation of the ICommand interface for the WPFWPF commanding system. 通常情况下,当执行 MouseGesture 时,将调用命令,尽管命令的行为会因命令特定的因素(如 CanExecute 值)而受到进一步的影响。In general, when the MouseGesture is executed, the command is invoked, although the command behavior is further influenced by command-specific factors such as the CanExecute value. 有关命令的详细信息,请参阅命令概述For more information on commanding, see the Commanding Overview.

可扩展应用程序标记语言 (XAML)Extensible Application Markup Language (XAML)中定义 MouseBinding 时,有两种方法可指定 MouseGestureWhen defining a MouseBinding in 可扩展应用程序标记语言 (XAML)Extensible Application Markup Language (XAML), there are two ways to specify the MouseGesture. XAMLXAML 中建立 MouseBinding 的第一种方法是定义 MouseBinding 元素的 Gesture 属性,这将启用语法以将鼠标操作和修饰符指定为单个字符串;例如,"CTRL + LeftClick"。The first way to establish a MouseBinding in XAMLXAML is to define the Gesture attribute of the MouseBinding element, which enables a syntax to specify mouse actions and modifiers as a single string; for example, "CTRL+LeftClick". 第二种方法是定义 MouseBinding 元素的 MouseAction 属性。The second way is to define the MouseAction attribute of the MouseBinding element. 设置 MouseGesture 的两种方法都是等效的,并且修改相同的基础对象,但如果两者都使用,则会发生冲突。Both ways of setting the MouseGesture are equivalent and modify the same underlying object, but there will be a conflict if both are used. 如果同时设置了 MouseActionGesture 属性,则手势会无效。In the case when the MouseAction and the Gesture attributes are both set, the gesture is invalid. 通常,建议您仅使用 XAMLXAML中的 Gesture 属性,即使您未指定修饰符;这可以避免多义性,提供最简洁的语法,并提供最简单的序列化表示形式。In general, it is recommended that you use only the Gesture attribute from XAMLXAML, even if you do not specify modifiers; this avoids ambiguity, provides the most streamlined syntax, and provides the most straightforward representation for serialization.

可以通过在 CommandManager 类上注册 RegisterClassInputBinding,在特定对象上或在类级别上定义 MouseBindingA MouseBinding can be defined on a specific object or at the class level by registering a RegisterClassInputBinding on the CommandManager class. 定义 MouseBinding 的最典型方法是在控件模板内,通过声明一个或多个 MouseBindingKeyBinding 元素来设置 XAMLXAML 中的 InputBindings 属性。The most typical way to define a MouseBinding is within the control template, setting the InputBindings property in XAMLXAML by declaring one or more MouseBinding or KeyBinding elements.

构造函数

MouseBinding()

初始化 MouseBinding 类的新实例。Initializes a new instance of the MouseBinding class.

MouseBinding(ICommand, MouseGesture)

用指定的命令和鼠标笔势初始化 MouseBinding 类的新实例。Initializes a new instance of the MouseBinding class, using the specified command and mouse gesture.

字段

MouseActionProperty

标识 MouseAction 依赖项属性。Identifies the MouseAction dependency property.

属性

CanFreeze

获取一个值,该值指示是否可将对象变为不可修改。Gets a value that indicates whether the object can be made unmodifiable.

(继承自 Freezable)
Command

获取或设置与此输入绑定关联的 ICommandGets or sets the ICommand associated with this input binding.

(继承自 InputBinding)
CommandParameter

获取或设置特定命令的命令特定数据。Gets or sets the command-specific data for a particular command.

(继承自 InputBinding)
CommandTarget

获取或设置命令的目标元素。Gets or sets the target element of the command.

(继承自 InputBinding)
DependencyObjectType

获取对此实例的 CLRCLR 类型进行包装的 DependencyObjectTypeGets the DependencyObjectType that wraps the CLRCLR type of this instance.

(继承自 DependencyObject)
Dispatcher

获取与此 Dispatcher 关联的 DispatcherObjectGets the Dispatcher this DispatcherObject is associated with.

(继承自 DispatcherObject)
Gesture

获取或设置与此 MouseBinding 关联的笔势。Gets or sets the gesture associated with this MouseBinding.

IsFrozen

获取一个值,该值指示对象当前是否可修改。Gets a value that indicates whether the object is currently modifiable.

(继承自 Freezable)
IsSealed

获取一个值,该值指示此实例当前是否为密封的(只读)。Gets a value that indicates whether this instance is currently sealed (read-only).

(继承自 DependencyObject)
MouseAction

获取或设置与此 MouseBinding 关联的 MouseActionGets or sets the MouseAction associated with this MouseBinding.

方法

CheckAccess()

确定调用线程是否可以访问此 DispatcherObjectDetermines whether the calling thread has access to this DispatcherObject.

(继承自 DispatcherObject)
ClearValue(DependencyProperty)

清除属性的本地值。Clears the local value of a property. 要清除的属性由 DependencyProperty 标识符指定。The property to be cleared is specified by a DependencyProperty identifier.

(继承自 DependencyObject)
ClearValue(DependencyPropertyKey)

清除只读属性的本地值。Clears the local value of a read-only property. 要清除的属性由 DependencyPropertyKey 指定。The property to be cleared is specified by a DependencyPropertyKey.

(继承自 DependencyObject)
Clone()

创建 Freezable 的可修改克隆,以制作该对象值的深层副本。Creates a modifiable clone of the Freezable, making deep copies of the object's values. 在复制此对象的依赖属性时,此方法会复制表达式(可能不再解析),但不复制动画或其当前值。When copying the object's dependency properties, this method copies expressions (which might no longer resolve) but not animations or their current values.

(继承自 Freezable)
CloneCore(Freezable)

复制指定对象的属性的基(未经过动画处理的)值。Copies the base (non-animated) values of the properties of the specified object.

CloneCore(Freezable)

复制指定对象的属性的基(未经过动画处理的)值。Copies the base (non-animated) values of the properties of the specified object.

(继承自 InputBinding)
CloneCurrentValue()

使用 Freezable 的当前值创建其可修改复本(深层副本)。Creates a modifiable clone (deep copy) of the Freezable using its current values.

(继承自 Freezable)
CloneCurrentValueCore(Freezable)

复制指定对象的属性的当前值。Copies the current values of the properties of the specified object.

CloneCurrentValueCore(Freezable)

复制指定对象的属性的当前值。Copies the current values of the properties of the specified object.

(继承自 InputBinding)
CoerceValue(DependencyProperty)

对指定依赖属性的值进行强制。Coerces the value of the specified dependency property. 通过对调用方 DependencyObject 上存在的依赖属性的属性元数据中所指定的任何 CoerceValueCallback 函数进行调用来完成此操作。This is accomplished by invoking any CoerceValueCallback function specified in property metadata for the dependency property as it exists on the calling DependencyObject.

(继承自 DependencyObject)
CreateInstance()

初始化 Freezable 类的新实例。Initializes a new instance of the Freezable class.

(继承自 Freezable)
CreateInstanceCore()

创建 MouseBinding 的实例。Creates an instance of an MouseBinding.

CreateInstanceCore()

创建 InputBinding 的实例。Creates an instance of an InputBinding.

(继承自 InputBinding)
Equals(Object)

确定提供的 DependencyObject 是否等效于当前 DependencyObjectDetermines whether a provided DependencyObject is equivalent to the current DependencyObject.

(继承自 DependencyObject)
Freeze()

使当前对象不可修改,并且将其 IsFrozen 属性设置为 trueMakes the current object unmodifiable and sets its IsFrozen property to true.

(继承自 Freezable)
FreezeCore(Boolean)

使 Freezable 对象变为不可修改或测试是否可将其变为不可修改。Makes the Freezable object unmodifiable or tests whether it can be made unmodifiable.

(继承自 Freezable)
GetAsFrozen()

使用基(未经过动画处理的)属性值创建 Freezable 的冻结副本。Creates a frozen copy of the Freezable, using base (non-animated) property values. 由于副本已冻结,因此将通过引用复制任何冻结的子对象。Because the copy is frozen, any frozen sub-objects are copied by reference.

(继承自 Freezable)
GetAsFrozenCore(Freezable)

使用基(非动画的)属性值让该实例成为指定的 Freezable 的冻结克隆。Creates the instance a frozen clone of the specified Freezable by using base (non-animated) property values.

GetAsFrozenCore(Freezable)

使用基(未经过动画处理的)属性值使该实例成为指定的 Freezable 的冻结复本。Makes the instance a frozen clone of the specified Freezable by using base (non-animated) property values.

(继承自 InputBinding)
GetCurrentValueAsFrozen()

使用当前属性值创建 Freezable 的冻结副本。Creates a frozen copy of the Freezable using current property values. 由于副本已冻结,因此将通过引用复制任何冻结的子对象。Because the copy is frozen, any frozen sub-objects are copied by reference.

(继承自 Freezable)
GetCurrentValueAsFrozenCore(Freezable)

将当前实例创建成指定的 Freezable 的冻结复本。Creates the current instance a frozen clone of the specified Freezable. 如果对象具有动画依赖属性,则复制其当前的动画值。If the object has animated dependency properties, their current animated values are copied.

GetCurrentValueAsFrozenCore(Freezable)

使当前实例成为指定 Freezable 的冻结克隆。Makes the current instance a frozen clone of the specified Freezable. 如果对象具有动画依赖属性,则复制其当前的动画值。If the object has animated dependency properties, their current animated values are copied.

(继承自 InputBinding)
GetHashCode()

获取此 DependencyObject 的哈希代码。Gets a hash code for this DependencyObject.

(继承自 DependencyObject)
GetLocalValueEnumerator()

创建一个专用的枚举数,用于确定哪些依赖项属性在此 DependencyObject 上具有以本地方式设置的值。Creates a specialized enumerator for determining which dependency properties have locally set values on this DependencyObject.

(继承自 DependencyObject)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
GetValue(DependencyProperty)

DependencyObject 的此实例返回依赖属性的当前有效值。Returns the current effective value of a dependency property on this instance of a DependencyObject.

(继承自 DependencyObject)
InvalidateProperty(DependencyProperty)

重新评估指定依赖属性的有效值。Re-evaluates the effective value for the specified dependency property.

(继承自 DependencyObject)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
OnChanged()

修改当前 Freezable 对象时调用。Called when the current Freezable object is modified.

(继承自 Freezable)
OnFreezablePropertyChanged(DependencyObject, DependencyObject)

确保为刚刚设置的 DependencyObjectType 数据成员建立适当的上下文指针。Ensures that appropriate context pointers are established for a DependencyObjectType data member that has just been set.

(继承自 Freezable)
OnFreezablePropertyChanged(DependencyObject, DependencyObject, DependencyProperty)

此成员支持 Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF) 基础结构,但不能在代码中直接使用。This member supports the Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF) infrastructure and is not intended to be used directly from your code.

(继承自 Freezable)
OnPropertyChanged(DependencyPropertyChangedEventArgs)

重写 OnPropertyChanged(DependencyPropertyChangedEventArgs)DependencyObject 实现,以同时调用任何响应类型 Freezable 不断变化的依赖属性的 Changed 处理程序。Overrides the DependencyObject implementation of OnPropertyChanged(DependencyPropertyChangedEventArgs) to also invoke any Changed handlers in response to a changing dependency property of type Freezable.

(继承自 Freezable)
OnPropertyChanged(DependencyPropertyChangedEventArgs)

每当更新此 DependencyObject 的任何依赖属性的有效值时调用。Invoked whenever the effective value of any dependency property on this DependencyObject has been updated. 更改的特定依赖属性将在事件数据中报告。The specific dependency property that changed is reported in the event data.

(继承自 DependencyObject)
ReadLocalValue(DependencyProperty)

如果存在,则返回依赖属性的本地值。Returns the local value of a dependency property, if it exists.

(继承自 DependencyObject)
ReadPreamble()

确保正在从有效的线程访问 FreezableEnsures that the Freezable is being accessed from a valid thread. Freezable 的继承者必须在任何 API 一开始读取不属于依赖项对象的数据成员时调用此方法。Inheritors of Freezable must call this method at the beginning of any API that reads data members that are not dependency properties.

(继承自 Freezable)
SetCurrentValue(DependencyProperty, Object)

设置依赖属性的值而不更改其值源。Sets the value of a dependency property without changing its value source.

(继承自 DependencyObject)
SetValue(DependencyProperty, Object)

设置依赖属性的本地值,该值由其依赖属性标识符指定。Sets the local value of a dependency property, specified by its dependency property identifier.

(继承自 DependencyObject)
SetValue(DependencyPropertyKey, Object)

设置一个只读依赖属性的本地值,该值由依赖属性的 DependencyPropertyKey 标识符指定。Sets the local value of a read-only dependency property, specified by the DependencyPropertyKey identifier of the dependency property.

(继承自 DependencyObject)
ShouldSerializeProperty(DependencyProperty)

返回一个值,该值指示序列化进程是否应序列化所提供的依赖属性的值。Returns a value that indicates whether serialization processes should serialize the value for the provided dependency property.

(继承自 DependencyObject)
ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)
VerifyAccess()

强制调用线程具有此 DispatcherObject 的访问权限。Enforces that the calling thread has access to this DispatcherObject.

(继承自 DispatcherObject)
WritePostscript()

引发 FreezableChanged 事件并调用其 OnChanged() 方法。Raises the Changed event for the Freezable and invokes its OnChanged() method. Freezable 派生的类应在修改的类成员不存储为依赖属性的任何 API 的末尾调用此方法。Classes that derive from Freezable should call this method at the end of any API that modifies class members that are not stored as dependency properties.

(继承自 Freezable)
WritePreamble()

验证 Freezable 是否未被冻结,并且是否正在从有效的线程上下文中访问它。Verifies that the Freezable is not frozen and that it is being accessed from a valid threading context. Freezable 的继承项应当在任何 API 一开始写入不属于依赖项属性的数据成员时调用此方法。Freezable inheritors should call this method at the beginning of any API that writes to data members that are not dependency properties.

(继承自 Freezable)

事件

Changed

在修改 Freezable 或其包含的对象时发生。Occurs when the Freezable or an object it contains is modified.

(继承自 Freezable)

适用于

另请参阅