PointerEventHandler 委托
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示将处理指针消息事件(如 PointerPressed)的方法。
public delegate void PointerEventHandler(Platform::Object ^ sender, PointerRoutedEventArgs ^ e);
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.Guid(3828898089, 49156, 19407, 137, 112, 53, 148, 134, 227, 159, 136)]
class PointerEventHandler : MulticastDelegate
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.Guid(3828898089, 49156, 19407, 137, 112, 53, 148, 134, 227, 159, 136)]
public delegate void PointerEventHandler(object sender, PointerRoutedEventArgs e);
Public Delegate Sub PointerEventHandler(sender As Object, e As PointerRoutedEventArgs)
参数
- sender
-
Object
Platform::Object
IInspectable
事件处理程序所附加到的对象。
事件的事件数据。
- 属性
Windows 要求
设备系列 |
Windows 10 (在 10.0.10240.0 中引入)
|
API contract |
Windows.Foundation.UniversalApiContract (在 v1.0 中引入)
|
示例
下面的代码示例演示 输入示例中的方案 2。 此代码显示了使用 PointerPressed、PointerReleased、PointerEntered、PointerExited 和 PointerMoved 事件的直接操作的一些使用模式。
<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>
<StackPanel Orientation="Horizontal" >
<ToggleSwitch x:Name="tbPointerCapture"
Header="Pointer Capture" FontSize="20"/>
<TextBlock x:Name="txtCaptureStatus"
Style="{StaticResource BasicTextStyle}"/>
</StackPanel>
<Border x:Name="bEnteredExited" Background="Red"
Height="300" Width="450" CornerRadius="20"
HorizontalAlignment="Left">
<Grid>
<TextBlock Style="{StaticResource BasicTextStyle}" Text=""
HorizontalAlignment="Center" VerticalAlignment="Center"
x:Name="bEnteredExitedTextBlock"/>
<Ellipse VerticalAlignment="Bottom" Stroke="Silver"
StrokeDashArray="2,2" StrokeThickness="2" Margin="2"
x:Name="bEnteredExitedTimer" Width="20" Height="20"
RenderTransformOrigin="0.5,0.5">
<Ellipse.RenderTransform >
<RotateTransform Angle="0" />
</Ellipse.RenderTransform>
</Ellipse>
</Grid>
</Border>
</StackPanel>
int _pointerCount;
public Scenario2()
{
this.InitializeComponent();
bEnteredExited.PointerEntered += bEnteredExited_PointerEntered;
bEnteredExited.PointerExited += bEnteredExited_PointerExited;
bEnteredExited.PointerPressed += bEnteredExited_PointerPressed;
bEnteredExited.PointerReleased += bEnteredExited_PointerReleased;
bEnteredExited.PointerMoved += bEnteredExited_PointerMoved;
// To code for multiple Pointers (that is, fingers),
// we track how many entered/exited.
_pointerCount = 0;
}
private void bEnteredExited_PointerMoved(object sender,
PointerRoutedEventArgs e)
{
Scenario2UpdateVisuals(sender as Border, "Moved");
}
private void bEnteredExited_PointerReleased(object sender,
PointerRoutedEventArgs e)
{
((Border)sender).ReleasePointerCapture(e.Pointer);
txtCaptureStatus.Text = string.Empty;
}
//Can only get capture on PointerPressed (i.e. touch down, mouse click, pen press)
private void bEnteredExited_PointerPressed(object sender,
PointerRoutedEventArgs e)
{
if (tbPointerCapture.IsOn)
{
bool _hasCapture = ((Border)sender).CapturePointer(e.Pointer);
txtCaptureStatus.Text = "Got Capture: " + _hasCapture;
}
}
private void bEnteredExited_PointerExited(object sender,
PointerRoutedEventArgs e)
{
_pointerCount--;
Scenario2UpdateVisuals(sender as Border, "Exited");
}
private void bEnteredExited_PointerEntered(object sender,
PointerRoutedEventArgs e)
{
_pointerCount++;
Scenario2UpdateVisuals(sender as Border, "Entered");
}
private void Scenario2UpdateVisuals(Border border,
String eventDescription)
{
switch (eventDescription.ToLower())
{
case "exited":
if (_pointerCount <= 0)
{
border.Background = new SolidColorBrush(Colors.Red);
bEnteredExitedTextBlock.Text = eventDescription;
}
break;
case "moved":
RotateTransform rt =
(RotateTransform)bEnteredExitedTimer.RenderTransform;
rt.Angle += 2;
if (rt.Angle > 360) rt.Angle -= 360;
break;
default:
border.Background = new SolidColorBrush(Colors.Green);
bEnteredExitedTextBlock.Text = eventDescription;
break;
}
}
private void Scenario2Reset(object sender, RoutedEventArgs e)
{
Scenario2Reset();
}
private void Scenario2Reset()
{
bEnteredExited.Background = new SolidColorBrush(Colors.Green);
bEnteredExitedTextBlock.Text = string.Empty;
}
Private _pointerCount As Integer
Public Sub New()
Me.InitializeComponent()
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)
Reset()
End Sub
Private Sub Reset()
bEnteredExited.Background = New SolidColorBrush(Colors.Green)
bEnteredExitedTextBlock.Text = String.Empty
End Sub
注解
此委托用于处理以下每个事件:
- PointerPressed
- PointerCanceled
- PointerCaptureLost
- PointerEntered
- PointerExited
- PointerMoved
- PointerReleased
- PointerWheelChanged