UWP Get Rotation Value (Angle) from Storyboard Animation During or After

389 views Asked by At

I'm manually making a carousel panel. I have a simple storyboard that rotates a grid which looks like a wheel.

    <Storyboard x:Name="MyStoryboard">
        <DoubleAnimation Duration="0, 0, 30" To="3000" FillBehavior="HoldEnd"  x:Name="myAnimation" 
         Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.Rotation)" 
         Storyboard.TargetName="Wheel" d:IsOptimized="True"/>
    </Storyboard>

The wheel is divided in 10 degree segments, so when the animation is manually stopped it must only rest on a multiple of 10 degrees. I read this article: MSDN: How to Set a Property After Animating it with a Storyboard The first two solutions don't seem to apply to UWP (a Storyboard.Remove method doesn't even exist) and I don't think the third applies to rotating a panel since I can't set a Storyboard as a dependency property for a Grid the way the example in the article does with a Button.

If I could somehow get the rotation value just as the storyboard is stopped, I could round it to the next multiple of 10 and set the DoubleAnimation.To value with it. Does anyone know how to grab this value (or a better way to do all of this)?

1

There are 1 answers

2
mm8 On BEST ANSWER

Does anyone know how to grab this value?

You can get the current value of the Rotation property from the CompositeTransform of your Wheel element like this:

private void PauseAnimation_Click(object sender, RoutedEventArgs e)
{
    MyStoryboard.Pause();
    CompositeTransform d = Wheel.RenderTransform as CompositeTransform;
    double rotation = d.Rotation;
 }