0

为什么下面的代码不会更改ScaleY1

  var transform = new ScaleTransform { ScaleY = 0 };
  var story = new Storyboard();
  var animation = new DoubleAnimation { 
                    Duration = new Duration(new TimeSpan(0)), To = 1 };
  Storyboard.SetTarget(animation, transform);
  Storyboard.SetTargetProperty(animation, new PropertyPath("ScaleY"));
  story.Children.Add(animation);
  story.Begin();

transform间接使用:它用于渲染一些UIElements并保存在它们的DependencyProperty.

4

1 回答 1

1

如果您放下情节提要并直接调用BeginAnimation可能会起作用吗?

var transform = new ScaleTransform { ScaleY = 0 };
var animation = new DoubleAnimation { Duration = TimeSpan.Zero, To = 1 };

transform.BeginAnimation(ScaleTransform.ScalyYProperty, animation);

请注意,只有当动画的FillBehavior值为 时,这才会有任何效果HoldEnd。否则,动画属性将立即恢复为其本地值(此处为 0)。幸运HoldEnd的是 的默认值FillBehavior

当然transform应该在某处使用。

于 2012-12-11T13:16:00.077 回答