PointerEventHandler delegate

PointerEventHandler delegate

Represents the method that will handle pointer message events such as PointerPressed.


Public Delegate Sub PointerEventHandler( 
  sender As Object,  
  e As PointerRoutedEventArgs 



Type: System.Object [.NET] | Platform::Object [C++]

The object where the event handler is attached.


Type: PointerRoutedEventArgs

Event data for the event.


This delegate is used for handling each of the following events:


The following code example shows scenario 2 from the Input sample. This code shows some usage patterns for direct manipulation using the PointerPressed, PointerReleased, PointerEntered, PointerExited, and PointerMoved events.

<StackPanel x:Name="Scenario2Output" ManipulationMode="All">
  <StackPanel Orientation="Horizontal" Margin="0,10,0,0">
    <Button x:Name="scenario2Reset" Content="Reset" 
      Margin="0,0,10,0" Click="Scenario2Reset"/>
  <StackPanel Orientation="Horizontal" >
    <ToggleSwitch x:Name="tbPointerCapture" 
      Header="Pointer Capture" FontSize="20"/>
    <TextBlock x:Name="txtCaptureStatus" 
      Style="{StaticResource BasicTextStyle}"/>
  <Border x:Name="bEnteredExited" Background="Red" 
    Height="300" Width="450" CornerRadius="20" 
      <TextBlock Style="{StaticResource BasicTextStyle}" Text="" 
        HorizontalAlignment="Center" VerticalAlignment="Center" 
      <Ellipse VerticalAlignment="Bottom" Stroke="Silver" 
        StrokeDashArray="2,2" StrokeThickness="2" Margin="2" 
        x:Name="bEnteredExitedTimer" Width="20" Height="20" 
        <Ellipse.RenderTransform >
          <RotateTransform Angle="0" />

Private _pointerCount As Integer

Public Sub New()
    AddHandler bEnteredExited.PointerEntered, AddressOf bEnteredExited_PointerEntered
    AddHandler bEnteredExited.PointerExited, AddressOf bEnteredExited_PointerExited
    AddHandler bEnteredExited.PointerPressed, AddressOf bEnteredExited_PointerPressed
    AddHandler bEnteredExited.PointerReleased, AddressOf bEnteredExited_PointerReleased
    AddHandler bEnteredExited.PointerMoved, AddressOf bEnteredExited_PointerMoved

    'To code for multiple Pointers (i.e. Fingers) we track how many entered/exited.
    _pointerCount = 0
End Sub

''' <summary>
''' Invoked when this page is about to be displayed in a Frame.
''' </summary>
''' <param name="e">Event data that describes how this page was reached.  The Parameter
''' property is typically used to configure the page.</param>
Protected Overrides Sub OnNavigatedTo(e As NavigationEventArgs)
End Sub

Private Sub bEnteredExited_PointerMoved(sender As Object, e As PointerRoutedEventArgs)
    Scenario2UpdateVisuals(TryCast(sender, Border), "Moved")
End Sub

Private Sub bEnteredExited_PointerReleased(sender As Object, e As PointerRoutedEventArgs)
    DirectCast(sender, Border).ReleasePointerCapture(e.Pointer)
    txtCaptureStatus.Text = String.Empty
End Sub

'Can only get capture on PointerPressed (i.e. touch down, mouse click, pen press)
Private Sub bEnteredExited_PointerPressed(sender As Object, e As PointerRoutedEventArgs)
    If tbPointerCapture.IsOn Then
        Dim _hasCapture As Boolean = DirectCast(sender, Border).CapturePointer(e.Pointer)
        txtCaptureStatus.Text = "Got Capture: " & _hasCapture
    End If
End Sub

Private Sub bEnteredExited_PointerExited(sender As Object, e As PointerRoutedEventArgs)
    _pointerCount -= 1
    Scenario2UpdateVisuals(TryCast(sender, Border), "Exited")
End Sub

Private Sub bEnteredExited_PointerEntered(sender As Object, e As PointerRoutedEventArgs)
    _pointerCount += 1
    Scenario2UpdateVisuals(TryCast(sender, Border), "Entered")

End Sub

Private Sub Scenario2UpdateVisuals(border As Border, eventDescription As String)
    Select Case eventDescription.ToLower()
        Case "exited"
            If _pointerCount <= 0 Then
                border.Background = New SolidColorBrush(Colors.Red)
                bEnteredExitedTextBlock.Text = eventDescription
            End If
            Exit Select
        Case "moved"

            Dim rt As RotateTransform = DirectCast(bEnteredExitedTimer.RenderTransform, RotateTransform)
            rt.Angle += 2
            If rt.Angle > 360 Then
                rt.Angle -= 360
            End If
            Exit Select
        Case Else
            border.Background = New SolidColorBrush(Colors.Green)
            bEnteredExitedTextBlock.Text = eventDescription
            Exit Select

    End Select
End Sub

Private Sub Scenario2ResetMethod(sender As Object, e As RoutedEventArgs)
End Sub

Private Sub Reset()
    bEnteredExited.Background = New SolidColorBrush(Colors.Green)
    bEnteredExitedTextBlock.Text = String.Empty
End Sub

Requirements (Windows 10 device family)

Device family

Universal, introduced version 10.0.10240.0

API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0


Windows::UI::Xaml::Input [C++]



Requirements (Windows 8.x and Windows Phone 8.x)

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

Windows Phone 8.1 [Windows Runtime apps only]


Windows::UI::Xaml::Input [C++]







© 2017 Microsoft