Reputation: 3
I am trying to let a WPF control move over a canvas. I'm doing that using two DoubleAnimations, set to the exact positions. Now I'm having a function that is supposed to move/"shift" the entire thing by an X and a Y value. The animation should move as well, while being played. However I can't manage to make that happen.
I have already tried having the shifting-function change the canvas-position, the From
and the To
values of both the animations accordingly, but for some reason, that didn't work.
// Object Initialization:
DoubleAnimation posX = new DoubleAnimation { From = Canvas.GetLeft(object), To = moveTo.X, Duration = TimeSpan.FromSeconds(1) };
DoubleAnimation posY = new DoubleAnimation { From = Canvas.GetTop(object), To = moveTo.Y, Duration = TimeSpan.FromSeconds(1) };
object.BeginAnimation(Canvas.LeftProperty, posX);
object.BeginAnimation(Canvas.TopProperty, posY);
// Shifting Function:
Canvas.SetLeft(object, Canvas.GetLeft(object) + X);
Canvas.SetTop(object, Canvas.GetTop(object) + Y);
posX.From += X;
posX.To += X;
posY.From += Y;
posY.To += Y;
I expected that code to shift/move/translate the object, and the (running, and by the way perfectly working) animation as well. Is there some problem I'm not aware of why that doesn't work? The object isn't affected by the shifting function at all.
Thanks in advance for any answers.
EDIT: Well I guess I'm not getting any answers.
Upvotes: 0
Views: 70