title: Using Silverlight DispatcherTimer - is there a better way (DependencyProperty on Animation)?
body: <p>I'm animating a 'race' on a map. The race takes 45 minutes, but the animation runs for 60 seconds.</p>
  
  <p>You can watch the <a href="http://racereplay.net/City2Surf/?ReplayId=768" rel="nofollow noreferrer">2008 City2Surf race demo</a> to see what I mean.</p>
  
  <p>The 'race clock' in the top-left must show "real time", and had to be set-up in the <code>.xaml.cs</code> with a <code>System.Windows.Threading.DispatcherTimer</code> which <strong>seems a bit of a hack</strong>. </p>
  
  <p>I thought maybe there'd be a DependencyProperty on the animation rather than just <code>StoryBoard.GetCurrentTime()</code>, but instead I have had to </p>
  
  <pre><code>         // SET UP AND START TIMER, before StoryBoard.Begin()
           dt = new System.Windows.Threading.DispatcherTimer();
           dt.Interval = new TimeSpan(0, 0, 0, 0, 100); // 0.1 second
           dt.Tick +=new EventHandler(dt_Tick);
           winTimeRatio = (realWinTime.TotalSeconds * 1.0) / animWinTime.TotalSeconds;
           dt.Start();
  </code></pre>
  
  <p>and then the <code>Tick</code> event handler</p>
  
  <pre><code>    void dt_Tick(object sender, EventArgs e)
      {
          var sb = LayoutRoot.Resources["Timeline"] as Storyboard;
          TimeSpan ts = sb.GetCurrentTime();
          TimeSpan toDisplay = new TimeSpan(0,0, 
                 Convert.ToInt32(ts.TotalSeconds * winTimeRatio));
          RaceTimeText.Text = toDisplay.ToString();
      }
  </code></pre>
  
  <p>This works and seems to perform OK - but my question is: am I missing something in the Silverlight animation/storyboard classes that would do this more neatly? I have to remember to <em>stop</em> the DispatcherTimer too!</p>
  
  <p>Or to put the question another way: any better suggestions on 'animation' of <code>TextBox</code> content (the <code>.Text</code> itself, not the location/dimensions/etc)? </p>