Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

MouseGesture Class

Defines a mouse input gesture that can be used to invoke a command.

Namespace:  System.Windows.Input
Assembly:  PresentationCore (in PresentationCore.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
[TypeConverterAttribute(typeof(MouseGestureConverter))]
public class MouseGesture : InputGesture
<MouseGesture .../>
<object property="mouseAction"/>
- or -
<object property="oneOrMoreModifierKeys+mouseAction"/>

XAML Values

mouseAction

MouseAction

A single mouse action.

oneOrMoreModifierKeys

One or more modifier keys, defined by the ModifierKeys enumeration. If more than one modifier key is provided, each modifier key is delimited with a "+" character.

The MouseGesture type exposes the following members.

  NameDescription
Public methodMouseGesture()Initializes a new instance of the MouseGesture class.
Public methodMouseGesture(MouseAction)Initializes a new instance of the MouseGesture class using the specified MouseAction.
Public methodMouseGesture(MouseAction, ModifierKeys)Initializes a new instance of the MouseGesture class using the specified MouseAction and ModifierKeys.
Top
  NameDescription
Public propertyModifiersGets or sets the modifier keys associated with this MouseGesture.
Public propertyMouseActionGets or sets the MouseAction associated with this gesture.
Top
  NameDescription
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodMatchesDetermines whether MouseGesture matches the input associated with the specified InputEventArgs object. (Overrides InputGesture.Matches(Object, InputEventArgs).)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

Unlike a KeyGesture, a MouseAction does not have to be paired with ModifierKeys to be a valid MouseGesture.

A MouseGesture can be bound to a RoutedCommand (or other ICommand implementations) through a MouseBinding so that the command is invoked when the MouseGesture occurs.

For MouseGesture XAML attribute usages, the property that is generally set in XAML is Gesture, in cases where the gesture can represent both a mouse action and one or more modifier key. You can also set the Gesture property to be just a mouse action. In general, it is recommended that you use only the Gesture attribute from XAML, rather than setting MouseAction, even if you do not specify modifiers. This will avoid ambiguity, provides the most streamlined syntax, and provides the most straightforward representation for serialization.

MouseGesture XAML object element usages are possible but uncommon, because you can ordinarily set the Gesture property of MouseBinding inline without the use of property element syntax. 

The following example shows to create a MouseGesture and associate it with a RoutedCommand through a MouseBinding. When the mouse wheel is clicked while the Control key is pressed, the Open is invoked.

<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);

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.