AndreyAkinshin
AndreyAkinshin

Reputation: 19011

ScaleY animation in WPF

Why below code doesn't change ScaleY to 1?

  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();

I use transform indirectly: it use for render some UIElements and kept in their DependencyProperty.

Upvotes: 0

Views: 268

Answers (1)

Clemens
Clemens

Reputation: 128013

Does it perhaps work if you drop the Storyboard and just call BeginAnimation directly?

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

transform.BeginAnimation(ScaleTransform.ScalyYProperty, animation);

Note that this will only have any effect if the animation's FillBehavior has a value of HoldEnd. Otherwise the animated property will immediately revert back to its local value (which is 0 here). Fortunately HoldEnd is the default value for FillBehavior.

And of course the transform should be used somewhere.

Upvotes: 1

Related Questions