Export (0) Print
Expand All

TouchExtensions.GetPosition Method

Gets the position of a TouchDevice, StylusDevice, or MouseDevice, relative to a specified IInputElement object.

Namespace: Microsoft.Surface.Presentation.Input
Assembly: Microsoft.Surface.Presentation (in Microsoft.Surface.Presentation)


public static Point GetPosition (
	InputDevice inputDevice,
	IInputElement relativeTo
/** @attribute ExtensionAttribute() */ 
public static Point GetPosition (
	InputDevice inputDevice, 
	IInputElement relativeTo
public static function GetPosition (
	inputDevice : InputDevice, 
	relativeTo : IInputElement
) : Point



The TouchDevice, StylusDevice, or MouseDevice to check. This is an implied parameter that specifies the object type that this method extends.


An IInputElement object. The returned position is calculated relative to this element. If relativeTo is null, the position is calculated relative to the root visual of the presentation source.

Return Value

Returns a Point object that defines the position of the input device relative to relativeTo.

This method extends InputDevice. The following code example shows how to call this method.

private void Grid_InputDown(object sender, InputEventArgs e)
    Point position = e.Device.GetPosition(myRectangle);

The preceding code example assumes that the Grid_InputDown method has been hooked up to the TouchDown event, using code similar to the following.

<Grid TouchDown="Grid_InputDown" TouchUp="Grid_InputUp" x:Name="MainGrid">
    <Rectangle x:Name="myRectangle" Height="20" Width="20"></Rectangle>
    <Ellipse x:Name="myEllipse" Height="20" Width="20"></Ellipse>
    <s:SurfaceTextBox x:Name="myTextBox" Height="20" Width="20"></s:SurfaceTextBox>

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.



Operating System (OS)Windows 7
Software Developer Kit (SDK)Surface 2.0
.NET Framework 4
Developer environmentVisual Studio 2010, Express or full edition
Microsoft Expression Blend 4.0 (optional)
End-user hardwareDevices made for Surface 2.0, or
Windows Touch computers

Did you find this information useful? Please send us your suggestions and comments.

© Microsoft Corporation. All rights reserved.
© 2014 Microsoft