How to create a managed control in WinRT?

I wrote UserControl in WinRT, and I want to make it movable with my finger.
When I move it with a pen or mouse, it is still moving, but not when I use my finger.
PointerMoved is not a trigger when I use my finger.

Here is a 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 am I missing here?

Edit:
I work with Windows 8.1 and VisualStudio 2013.
Perhaps this is a new feature ^^

+4
source share
2 answers

It is easier 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; } 

Good luck

+8
source

Firstly, I’m not sure that you can move the pen or mouse, because in the PointerMoved event you should check the boolean value of e.Pointer.IsInContact to make sure that you select the object when moving. It makes your moving action look better.

Secondly, I'm sorry that I do not know why in your machine PointerMoved does not start when using a finger. In any case, it would be better if you set the function name of your handler differently from the event name.

If you can share more information, we can discuss.

0
source

Source: https://habr.com/ru/post/1492765/


All Articles