Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>My experience comes from 2D animation, but I guess the problem is the same.</p> <p>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 <a href="http://msdn.microsoft.com/en-us/library/ms742868.aspx" rel="nofollow">Storyboards Overview</a>.) 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.</p> <p>The solution is:</p> <ul> <li>Create a naming scope around the element that will govern the transform.</li> <li>Call RegisterName() for each Freezable object being animated.</li> <li>Pass the element to Storyboard.Begin()</li> </ul> <p>Which would make your code look something like this (not tested):</p> <pre><code>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); </code></pre> <p>None of this is necessary in XAML because your objects are automatically registered.</p> <p>EDIT: But then I worked out that you can simplify things by leaving out the Storyboard altogether:</p> <pre><code>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); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload