WPF animation problem when using Storyboard from code?

My experience comes from 2D animation, but I guess the problem is the same For some stupid reason (probably relating to an unhealthy focus on XAML), Storyboards can only animate Freezable objects by looking them up by name. (See example in Storyboards Overview ) Thus although you provide a reference to your 'rotation' object when you call Storyboard. SetTarget(animation, rotation), the Storyboard only wants to remember and use a name, which it does not have The solution is: Create a naming scope around the element that will govern the transform Call RegisterName() for each Freezable object being animated Pass the element to Storyboard.Begin() Which would make your code look something like this (not tested): FrameworkContentElement element = new FrameworkContentElement(); NameScope.

SetNameScope(element, new NameScope()); RotateTransform3D tempTransform = (RotateTransform3D)wheel. Transform; AxisAngleRotation3D rotation = (AxisAngleRotation3D)tempTransform. Rotation; element.

RegisterName("rotation", rotation); Storyboard storyboard = new Storyboard(); DoubleAnimation animation = new DoubleAnimation(); animation. By = defaultAngle; animation. Duration = TimeSpan.

FromSeconds(.5); Storyboard. SetTarget(animation, rotation); Storyboard. SetTargetProperty(animation, new PropertyPath("Angle")); storyboard.Children.

Add(animation); storyboard. Duration = animation. Duration; storyboard.

Begin(element, HandoffBehavior. Compose) None of this is necessary in XAML because your objects are automatically registered EDIT: But then I worked out that you can simplify things by leaving out the Storyboard altogether: var T = new TranslateTransform(40, 0); Duration duration = new Duration(new TimeSpan(0, 0, 0, 1, 0); DoubleAnimation anim = new DoubleAnimation(30, duration); T. BeginAnimation(TranslateTransform.

YProperty, anim).

My experience comes from 2D animation, but I guess the problem is the same. For some stupid reason (probably relating to an unhealthy focus on XAML), Storyboards can only animate Freezable objects by looking them up by name. (See example in Storyboards Overview.) Thus although you provide a reference to your 'rotation' object when you call Storyboard.

SetTarget(animation, rotation), the Storyboard only wants to remember and use a name, which it does not have. The solution is: Create a naming scope around the element that will govern the transform. Call RegisterName() for each Freezable object being animated.

Pass the element to Storyboard.Begin() Which would make your code look something like this (not tested): FrameworkContentElement element = new FrameworkContentElement(); NameScope. SetNameScope(element, new NameScope()); RotateTransform3D tempTransform = (RotateTransform3D)wheel. Transform; AxisAngleRotation3D rotation = (AxisAngleRotation3D)tempTransform.

Rotation; element. RegisterName("rotation", rotation); Storyboard storyboard = new Storyboard(); DoubleAnimation animation = new DoubleAnimation(); animation.By = defaultAngle; animation. Duration = TimeSpan.

FromSeconds(.5); Storyboard. SetTarget(animation, rotation); Storyboard. SetTargetProperty(animation, new PropertyPath("Angle")); storyboard.Children.

Add(animation); storyboard. Duration = animation. Duration; storyboard.

Begin(element, HandoffBehavior. Compose); None of this is necessary in XAML because your objects are automatically registered. EDIT: But then I worked out that you can simplify things by leaving out the Storyboard altogether: var T = new TranslateTransform(40, 0); Duration duration = new Duration(new TimeSpan(0, 0, 0, 1, 0); DoubleAnimation anim = new DoubleAnimation(30, duration); T.

BeginAnimation(TranslateTransform. YProperty, anim).

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions