Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>On the storyboard there is a SpeedRatio setting which is a multiplier to the duration. You cannot bind to this however as it is not a dependency property.</p> <p>To get around this you can use the SetSpeedRatio function on the storyboard. Note this only works if the story board is started in code (other wise you get an error).</p> <p>The code below is an full example of how you would raise event in an object to effect the speed of the animation of a spinning rectangle. The purpose of the textbox and data bindings are to update the background object. The button is just so the textbox looses focus and updates the object.</p> <pre><code>&lt;Window x:Class="WpfApplication1.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="300" Width="300"&gt; &lt;StackPanel&gt; &lt;Rectangle Margin="50" Width="50" Height="50" Fill="Red" x:Name="rc"&gt; &lt;Rectangle.RenderTransform&gt; &lt;RotateTransform x:Name="TransRotate" CenterX="25" CenterY="25" Angle="0" /&gt; &lt;/Rectangle.RenderTransform&gt; &lt;Rectangle.Resources&gt; &lt;Storyboard x:Key="spin"&gt; &lt;DoubleAnimation x:Name="da" Storyboard.TargetName="TransRotate" Storyboard.TargetProperty="Angle" By="360" Duration="0:0:10" AutoReverse="False" RepeatBehavior="Forever" /&gt; &lt;/Storyboard&gt; &lt;/Rectangle.Resources&gt; &lt;/Rectangle&gt; &lt;TextBox Text="{Binding Speed}" /&gt; &lt;Button&gt;Update Speed&lt;/Button&gt; &lt;/StackPanel&gt; &lt;/Window&gt; </code></pre> <p>Then the C# code</p> <pre><code>{ public Window1() { InitializeComponent(); //create new object BackgroundObject bo = new BackgroundObject(); //binding only needed for the text box to change speed value this.DataContext = bo; //Hook up event bo.SpeedChanged += bo_SpeedChanged; //Needed to prevent an error Storyboard sb = (Storyboard)rc.FindResource("spin"); sb.Begin(); } //Change Speed public void bo_SpeedChanged( object sender, int newSpeed) { Storyboard sb = (Storyboard)rc.FindResource("spin"); sb.SetSpeedRatio(newSpeed); } } public delegate void SpeedChangedEventHandler(object sender, int newSpeed); public class BackgroundObject { public BackgroundObject() { _speed = 10; } public event SpeedChangedEventHandler SpeedChanged; private int _speed; public int Speed { get { return _speed; } set { _speed = value; SpeedChanged(this,value); } } } </code></pre> <p>I am sure you can adapt to your usage.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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