Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't set Storyboard.TargetProperty to CompositeTransform.Rotation in Metro style app from code
    text
    copied!<p>I'm messing around with some Storyboards in a Metro XAML app. I have to create a <code>Storyboard</code> in code. I'd like to set the <code>Storyboard.TargetProperty</code> to <code>CompositeTransform.Rotation</code></p> <p>It seems impossible...</p> <p>My Storyboard in XAML looks like this:</p> <pre><code>&lt;Storyboard&gt; &lt;DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.Rotation)" Storyboard.TargetName="grid"&gt; &lt;EasingDoubleKeyFrame KeyTime="0" Value="0"/&gt; &lt;EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="60"/ &lt;/DoubleAnimationUsingKeyFrames&gt; &lt;/Storyboard&gt; </code></pre> <p>I'd like to create something similar.<br/> <strong>Important:</strong> I am not trying to <em>recreate</em> this exact Storyboard. I am inside the code of a custom <code>ContentControl</code>, so <code>this</code> is the <code>Control</code>, and there's no "grid" to target the animation to. The target is the control itself, which has <code>CompositeTransform</code> previously set.<br/><br/> My code so far is like this:</p> <pre><code>var turnSB = new Storyboard(); var doubleAnim = new DoubleAnimationUsingKeyFrames(); doubleAnim.KeyFrames.Add(new EasingDoubleKeyFrame() { KeyTime = TimeSpan.FromMilliseconds(0), Value = currentAngle }); doubleAnim.KeyFrames.Add(new EasingDoubleKeyFrame() { KeyTime = TimeSpan.FromMilliseconds(500), Value = targetAngle }); turnSB.Children.Add(doubleAnim); Storyboard.SetTarget(doubleAnim, this.RenderTransform); Storyboard.SetTargetProperty(doubleAnim, "(CompositeTransform.Rotation)"); turnSB.Begin(); </code></pre> <p>As soon as it hits the Begin method I get an Exception saying that (CompositeTransform.Rotation) cannot be resolved. So I'm guessing I didn't got the property path quite right. I've tried different variations, but according to PropertyPaths, this should be the correct one, shouldn't it? :S</p> <p>If this is an unsolvable problem, I'm open to suggestions on a workaround...</p> <p><strong>EDIT:</strong></p> <p>I think I have solved the problem for now. I have some interesting findings though... <br/><br/> If I make a UserControl I can do practically anything. Everything works, I can set the Storyboard.Targetproperty, and the animation plays correctly. <br/><br/> However if I use a custom control, or inherit from another control (say ContentControl), I can't start a Storyboard from code, only in some cases. <br/><br/> For example: If I make a storyboard (defined in XAML) to animate Rotation (or any transformation property for that matter) and try to start from code, I get the above exception. But If I animate a simple property, say Opacity, it works fine. <br/>(I did the same with a UserControl, and it worked.) <br/> <br/> Can someone explain this?</p>
 

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