-api-id | -api-type |
---|---|
P:Windows.UI.Input.PointerPointProperties.IsPrimary |
winrt property |
Gets a value that indicates whether the input is from the primary pointer when multiple pointers are registered.
True if the input is from the pointer designated as primary; otherwise false.
The primary pointer is a single pointer (touch, mouse, and pen/stylus) in the current interaction.
For mouse, the primary pointer is the only pointer for which mouse events can be generated.
For touch (where there can be multiple concurrent pointers), the primary pointer is the first contact in an interaction. For any interaction after the first PointerPressed event, IsPrimary returns false.
A new primary pointer is only registered when all contacts in that interaction are removed and a new contact is subsequently detected.
A primary pointer can perform actions that are not available to other pointers. For example, when a primary pointer generates a WM_POINTERDOWN message on an inactive window, a WM_POINTERACTIVATE] message is also sent to that window.
This example uses different colored ellipses to show whether the pointer associated with the PointerRoutedEventArgs is the primary pointer.
private void MainPage_PointerPressed(object sender, PointerRoutedEventArgs e)
{
PointerPoint pt = e.GetCurrentPoint(pointerCanvas);
contacts[pt.PointerId] = pt;
PointerCounter.Text = contacts.Count.ToString();
Ellipse ellipse = new Ellipse();
ellipse.StrokeThickness = 2;
ellipse.Width = ellipseDiameter;
ellipse.Height = ellipseDiameter;
ellipse.Tag = pt.PointerId;
TranslateTransform translate = new TranslateTransform();
translate.X = pt.Position.X - ellipseDiameter / 2;
translate.Y = pt.Position.Y - ellipseDiameter / 2;
ellipse.RenderTransform = translate;
pointerCanvas.Children.Add(ellipse);
if (pt.Properties.IsPrimary == true)
{
primaryPointer = pt;
primaryEllipse = ellipse;
primaryEllipse.Scale(scaleX: 2, scaleY: 2, centerX: 0, centerY: 0).Start();
ellipse.Stroke = new SolidColorBrush(Windows.UI.ColorHelper.FromArgb(255, 255, 0, 0));
// Create the transform
ScaleTransform scaleTransform = new ScaleTransform();
scaleTransform.ScaleX = primaryEllipse.Width * 1.25;
scaleTransform.ScaleY = primaryEllipse.Height * 1.25;
primaryEllipse.RenderTransform = scaleTransform;
PointerPrimary.Text = pt.PointerId.ToString();
}
else
ellipse.Stroke = new SolidColorBrush(Windows.UI.ColorHelper.FromArgb(255, 0, 0, 255));
e.Handled = true;
}