Why don't these animations work when I'm using a storyboard?

前端 未结 2 1776
清酒与你
清酒与你 2020-12-01 13:32

I\'ve created a simple subclass of StackPanel that I can move around on the screen using an animated TranslateTransform. It looks like this:

2条回答
  •  离开以前
    2020-12-01 13:56

    It's property path syntax. The following approach works:

    public void BeginMove(Point translatePosition)
    {
      RenderTransform = new TranslateTransform();
      Duration d = new Duration(new TimeSpan(0, 0, 0, 0, 400));
      DoubleAnimation x = new DoubleAnimation(translatePosition.X, d);
      DoubleAnimation y = new DoubleAnimation(translatePosition.Y, d);
    
      Storyboard.SetTarget(x, this);
      Storyboard.SetTargetProperty(x, 
                  new PropertyPath("(UIElement.RenderTransform).(TranslateTransform.X)"));
    
      Storyboard.SetTarget(y, this);
      Storyboard.SetTargetProperty(y, 
                  new PropertyPath("(UIElement.RenderTransform).(TranslateTransform.Y)"));
    
      Storyboard sb = new Storyboard();
      sb.Children.Add(x);
      sb.Children.Add(y);
      sb.Completed += sb_Completed;
      sb.Begin();
    
      //RenderTransform.BeginAnimation(TranslateTransform.XProperty, x);
      //RenderTransform.BeginAnimation(TranslateTransform.YProperty, y);
    }
    

提交回复
热议问题