wpfsilverlightdata-bindinganimationvisualstatemanager

How can I control the SpeedRatio of a Storyboard inside a VisualState?


Given a Storyboard started by the VisualStateManager as part of a ControlTemplate, how would I adjust the SpeedRatio of that animation based on property changes of the control?

<ControlTemplate>
  <Grid>
    <VisualStateManager.VisualStateGroups>
      <VisualStateGroup>
        <VisualState>
          <Storyboard Name="SpinningThing"
                      SpeedRatio="{Binding SpinningSpeedRatio}">
            ...

This needs to work in both WPF and Silverlight.

I don't think I can set a binding there for a number of reasons. Foremost, Storyboard is Freezable so you can't just go setting the SpeedRatio all willy-nilly in WPF. But, if it's started by the VisualStateManager, can I call SetSpeedRatio on it?

Also, since its parent is a VisualState, doesn't that mean there would be no governing FrameworkElement to relate to for it?

So, if I can't do it with a binding, how can this be done?


Solution

  • Alright, so it looks like there really is no way to handle this strictly with a binding. So to account for it, I have hooked events in the code-behind to start/adjust the animations as appropriate.