你必須使用一個DependencyProperty
動畫
public class DragAdorner
{
public Point Position
{
get { return (Point)GetValue(PositionProperty); }
set { SetValue(PositionProperty, value); }
}
// Using a DependencyProperty as the backing store for PositionProperty. This enables animation, styling, binding, etc...
public static readonly DependencyProperty PositionProperty =
DependencyProperty.Register("Position", typeof(Point), typeof(DragAdorner), new UIPropertyMetadata(PositionChanged));
private static void PositionChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
{
UpdatePosition(Position);
}
}
然後,你可以做這樣的事情(未測試)
double xPosLocation = (int)(dividerDistanceXAxis * virtualPosition) + YAxisData.SpacingLeft;
double yPosLocation = CalculateValueToYPosition(VirtualPriceOfVehicle);
Point newLocation = new Point(xPosLocation, yPosLocation);
PointAnimation myPointAnimation = new PointAnimation();
myPointAnimation.From = DragAdorner.Position;
myPointAnimation.To = newLocation;
myPointAnimation.Duration = new Duration(TimeSpan.FromSeconds(1));
Storyboard myStoryboard = new Storyboard();
myStoryboard.Children.Add(myPointAnimation);
Storyboard.SetTargetName(myPointAnimation, DragAdorner.Position);
myStoryboard.Begin();
來源
2012-01-09 14:18:25
LPL