PointerRoutedEventArgs 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
包含最後一個指標事件訊息所傳回的引數。
public ref class PointerRoutedEventArgs sealed : RoutedEventArgs
/// [Windows.Foundation.Metadata.ContractVersion(Microsoft.UI.Xaml.WinUIContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class PointerRoutedEventArgs final : RoutedEventArgs
[Windows.Foundation.Metadata.ContractVersion(typeof(Microsoft.UI.Xaml.WinUIContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class PointerRoutedEventArgs : RoutedEventArgs
Public NotInheritable Class PointerRoutedEventArgs
Inherits RoutedEventArgs
- 繼承
- 屬性
範例
下列程式碼範例顯示 輸入範例中的案例 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;
}
備註
在大部分情況下,建議您透過指標事件處理常式的事件引數取得指標資訊。
如果事件引數未內建公開應用程式所需的指標詳細資料,您可以透過 的 PointerRoutedEventArgs
GetCurrentPoint和GetIntermediatePoints方法來存取擴充指標資料。 使用這些方法來指定指標資料的內容。
事件 PointerRoutedEventArgs
資料類別用於這些事件:
- PointerPressed
- PointerCanceled
- PointerCaptureLost
- PointerEntered
- PointerExited
- PointerMoved
- PointerReleased
- PointerWheelChanged
重要
滑鼠輸入會與第一次偵測到滑鼠輸入時指派的單一指標相關聯。 按一下滑鼠按鈕 (左鍵、滾輪或右鍵) 會透過 PointerPressed 事件建立指標與該按鈕的次要關聯。 只在放開相同的滑鼠按鈕時才會觸發 PointerReleased 事件 (這個事件完成前,沒有其他按鈕可以與該指標關聯)。 由於這個專屬關聯的關係,其他滑鼠按鈕的按一下都會經由 PointerMoved 事件進行路由。 您可以在處理此事件時測試滑鼠按鍵狀態,如下列範例所示。
private void Target_PointerMoved(object sender, PointerRoutedEventArgs e)
{
Pointer ptr = e.Pointer;
// Multiple, simultaneous mouse button inputs are processed here.
// Mouse input is associated with a single pointer assigned when
// mouse input is first detected.
// Clicking additional mouse buttons (left, wheel, or right) during
// the interaction creates secondary associations between those buttons
// and the pointer through the pointer pressed event.
// The pointer released event is fired only when the last mouse button
// associated with the interaction (not necessarily the initial button)
// is released.
// Because of this exclusive association, other mouse button clicks are
// routed through the pointer move event.
if (ptr.PointerDeviceType == PointerDeviceType.Mouse)
{
// To get mouse state, we need extended pointer details.
// We get the pointer info through the getCurrentPoint method
// of the event argument.
PointerPoint ptrPt = e.GetCurrentPoint(Target);
if (ptrPt.Properties.IsLeftButtonPressed)
{
eventLog.Text += "\nLeft button: " + ptrPt.PointerId;
}
if (ptrPt.Properties.IsMiddleButtonPressed)
{
eventLog.Text += "\nWheel button: " + ptrPt.PointerId;
}
if (ptrPt.Properties.IsRightButtonPressed)
{
eventLog.Text += "\nRight button: " + ptrPt.PointerId;
}
}
// Prevent most handlers along the event route from handling the same event again.
e.Handled = true;
// Display pointer details.
updateInfoPop(e);
}
- 傳送者 (的值,其位於委派簽章上,而不是這個事件資料類別) 。
- PointerRoutedEventArgs 的特定成員,例如 KeyModifiers 或 GetCurrentPoint。
- 指標裝置描述類別的值。 從 Pointer 屬性取得 Pointer 。
- 來自 PointerPoint系統輸入概念化的成員。 使用GetCurrentPoint API 取得 PointerPoint值,然後呼叫PointerPoint.Position和PointerPointProperties 等 PointerPoint API。
特定事件通常具有各種指標裝置和指標點類別中的資訊,主要與該事件相關。 例如,當您處理PointerWheelChanged時,您可能對PointerPointProperties中的MouseWheelDelta感興趣。
和 GetIntermediatePoints
方法所擷 GetCurrentPoint
取的物件會透過Properties屬性提供擴充指標資訊的存取權,這個屬性會取得PointerPointProperties物件。
在下列範例中,我們會透過PointerPoint 和 PointerPointProperties物件取得擴充指標屬性。 (請參閱處理完整的 example.) 指標輸入
String queryPointer(PointerPoint ptrPt)
{
String details = "";
switch (ptrPt.PointerDeviceType)
{
case PointerDeviceType.Mouse:
details += "\nPointer type: mouse";
break;
case PointerDeviceType.Pen:
details += "\nPointer type: pen";
if (ptrPt.IsInContact)
{
details += "\nPressure: " + ptrPt.Properties.Pressure;
details += "\nrotation: " + ptrPt.Properties.Orientation;
details += "\nTilt X: " + ptrPt.Properties.XTilt;
details += "\nTilt Y: " + ptrPt.Properties.YTilt;
details += "\nBarrel button pressed: " + ptrPt.Properties.IsBarrelButtonPressed;
}
break;
case PointerDeviceType.Touch:
details += "\nPointer type: touch";
details += "\nrotation: " + ptrPt.Properties.Orientation;
details += "\nTilt X: " + ptrPt.Properties.XTilt;
details += "\nTilt Y: " + ptrPt.Properties.YTilt;
break;
default:
details += "\nPointer type: n/a";
break;
}
GeneralTransform gt = Target.TransformToVisual(panel);
Point screenPoint;
screenPoint = gt.TransformPoint(new Point(ptrPt.Position.X, ptrPt.Position.Y));
details += "\nPointer Id: " + ptrPt.PointerId.ToString() +
"\nPointer location (parent): " + ptrPt.Position.X + ", " + ptrPt.Position.Y +
"\nPointer location (screen): " + screenPoint.X + ", " + screenPoint.Y;
return details;
}
一般而言,此方法傳回的物件是用來將指標資料摘要至 GestureRecognizer。 另一個案例是取得PointerWheelChanged事件的MouseWheelDelta;該值位於PointerPointProperties中。
屬性
Handled |
取得或設定值,這個值會將路由事件標示為已處理,並防止事件路由中的大部分處理常式再次處理相同的事件。 |
IsGenerated |
取得值,這個值表示指標事件是從使用者與物件直接互動發生,還是由平臺根據應用程式的 UI 變更而產生。 |
KeyModifiers |
取得值,這個值表示起始指標事件時,哪些索引鍵修飾詞作用中。 |
OriginalSource |
取得引發事件之 物件的參考。 這通常是控制項的範本部分,而不是在應用程式 UI 中宣告的專案。 (繼承來源 RoutedEventArgs) |
Pointer |
取得指標標記的參考。 |
方法
GetCurrentPoint(UIElement) |
擷取 PointerPoint 物件,提供與事件相關聯之指標的基本資訊。 |
GetIntermediatePoints(UIElement) |
從最後一個指標事件擷取 PointerPoint 物件的集合,這些物件代表最後一個指標事件的指標歷程記錄,並包含目前的指標事件。 集合中的每個 PointerPoint 都會提供有關與事件相關聯之指標的基本資訊。 集合中的最後一個專案相當於GetCurrentPoint所傳回的PointerPoint物件。 |