8

It seems I can't do myObject.BeginAnimation(dp , animation).

Is this a bug or has it been changed?

6
  • 2
    please post what code you have so we may be able to see how you are instantiating myObject
    – MethodMan
    Dec 25, 2011 at 19:13
  • 1
    It doesn't matter what object. Even Button myButton = new Button() doesn't have the BeginAnimation method. I'm not sure whether this was changed or my installation is broken...
    – Leonardo C
    Dec 25, 2011 at 19:15
  • 1
    @HarisHasan So are there any alternatives? How else can I use my DoubleAnimation?
    – Leonardo C
    Dec 25, 2011 at 19:24
  • I would suggest see animation samples code.msdn.microsoft.com/windowsapps/… Dec 25, 2011 at 19:26
  • @HarisHasan thanks but none of them show how to do it in code. They are XAML animations
    – Leonardo C
    Dec 25, 2011 at 19:28

1 Answer 1

7

You need to use a storyboard. Add your animation to the storyboard and have the storyboard begin the animation.

var storyboard = new Storyboard();

var opacityAnimation = new DoubleAnimation { 
    From = 0,
    To = 1,
    Duration = DurationHelper.FromTimeSpan(TimeSpan.FromSeconds(1)),
};
storyboard.Children.Add(opacityAnimation);

Storyboard.SetTargetProperty(opacityAnimation, "Opacity");
Storyboard.SetTarget(storyboard, myObject);

storyboard.Begin();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.