I have a weird problem, I register in a Grid to the event TouchMove
_outerGrid.TouchMove += _outerGrid_TouchMove;
I save the last touch point, and calculate the displacements between the last and the actual touch point.
double dx = actualPoint.X - _lastMovePoint.X;
double dy = actualPoint.Y - _lastMovePoint.Y;
Now if I try to move a UIElement accordingly, I get that the Y property updates correctly, but the X does not.
TransformGroup tg = element.RenderTransform as TransformGroup;
TranslateTransform t = tg.Children[1] as TranslateTransform;
t.X += dx; //Remains unchanged after the sum, and dx != 0
t.Y += dy;
I have previously created a TransformGroup with a ScaleTransform and a TranslateTransform to place the element in the right position with an animation... now if I try to move it around it doesn't work
double startPointX = -100;
double accelRatio = 0.5;
double decelRatio = 0.5;
element.RenderTransformOrigin = new Point(0.5, 0.5);
TransformGroup tg = tg = new TransformGroup();
TranslateTransform t = new TranslateTransform();
ScaleTransform s = new ScaleTransform();
tg.Children.Add(s);
tg.Children.Add(t);
element.RenderTransform = tg;
DoubleAnimation xAnim = new DoubleAnimation();
xAnim.From = displX - startPointX;
xAnim.To = displX;
xAnim.Duration = TimeSpan.FromMilliseconds(dur);
xAnim.BeginTime = TimeSpan.FromMilliseconds(delay);
xAnim.AccelerationRatio = accelRatio;
xAnim.DecelerationRatio = decelRatio;
DoubleAnimation sAnim = new DoubleAnimation();
sAnim.From = 0;
sAnim.To = 1;
sAnim.Duration = TimeSpan.FromMilliseconds(dur);
sAnim.BeginTime = TimeSpan.FromMilliseconds(delay);
DoubleAnimation oAnim = new DoubleAnimation();
oAnim.From = 0;
oAnim.To = 1;
oAnim.Duration = TimeSpan.FromMilliseconds(dur);
oAnim.BeginTime = TimeSpan.FromMilliseconds(delay);
s.BeginAnimation(ScaleTransform.ScaleXProperty, sAnim);
s.BeginAnimation(ScaleTransform.ScaleYProperty, sAnim);
t.BeginAnimation(TranslateTransform.XProperty, xAnim);
t.Y = displY;
element.BeginAnimation(OpacityProperty, oAnim);
I noticed that if I animate the Y property in the way I animate the X, also the Y starts to have the same problem. So it has something to do with animating the property and later trying to set it
Someone has any ideas of what can be causing this behaviour?
Thank you.