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