PointerEventHandler Delegado
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Representa el método que controlará eventos de mensaje de puntero como PointerPressed.
public delegate void PointerEventHandler(Platform::Object ^ sender, PointerRoutedEventArgs ^ e);
[Windows.Foundation.Metadata.ContractVersion(typeof(Microsoft.UI.Xaml.WinUIContract), 65536)]
[Windows.Foundation.Metadata.Guid(2760536545, 35764, 21911, 158, 49, 144, 58, 63, 106, 4, 251)]
public delegate void PointerEventHandler(object sender, PointerRoutedEventArgs e);
Public Delegate Sub PointerEventHandler(sender As Object, e As PointerRoutedEventArgs)
Parámetros
- sender
-
Object
Platform::Object
Objeto en que está asociado el controlador de eventos.
Datos del evento.
- Atributos
Ejemplos
En el ejemplo de código siguiente se muestra el escenario 2 del ejemplo de entrada. Este código muestra algunos patrones de uso para la manipulación directa mediante los eventos PointerPressed, PointerReleased, PointerEntered, PointerExited y 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;
}
Comentarios
Este delegado se usa para controlar cada uno de los siguientes eventos:
- PointerPressed
- PointerCanceled
- PointerCaptureLost
- PointerEntered
- PointerExited
- PointerMoved
- PointerReleased
- PointerWheelChanged