I wrote a UserControl in WinRT and I want to make it moveable with a finger.
When I move it using a pen or mouse it is still moving but not when i use a finger.
The PointerMoved is not triggert when I use a finger.
Here is the simple xaml:
<UserControl>
<Rectangle PointerPressed="PointerPressed" PointerMoved="PointerMoved"/>
</UserControl>
and here is the code:
private Point position;
void PointerPressed(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
{
Rectangle r = sender as Rectangle;
var pointerPoint = e.GetCurrentPoint(r);
position = pointerPoint.Position;
}
void PointerMoved(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
{
Rectangle r = sender as Rectangle;
var delta = e.GetCurrentPoint(r).Position;
r.Margin = new Thickness(r.Margin.Left + delta.X - position.X, r.Margin.Top + delta.Y - position.Y, 0, 0);
}
What do I miss here?
Edit:
I am working with Windows 8.1 and VisualStudio 2013.
Maybe it's a new feature^^
It's simpler than you think!
<Rectangle Width="100" Height="100" Fill="White"
ManipulationMode="TranslateX,TranslateY"
ManipulationDelta="Rectangle_ManipulationDelta_1" />
private void Rectangle_ManipulationDelta_1(object sender, ManipulationDeltaRoutedEventArgs e)
{
var _Rectangle = sender as Windows.UI.Xaml.Shapes.Rectangle;
var _Transform = (_Rectangle.RenderTransform as CompositeTransform)
?? (_Rectangle.RenderTransform = new CompositeTransform()) as CompositeTransform;
_Transform.TranslateX += e.Delta.Translation.X;
_Transform.TranslateY += e.Delta.Translation.Y;
}
Best of luck!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With