Skip to content

Instantly share code, notes, and snippets.

@ianbishop
Created November 15, 2012 03:02
Show Gist options
  • Select an option

  • Save ianbishop/4076381 to your computer and use it in GitHub Desktop.

Select an option

Save ianbishop/4076381 to your computer and use it in GitHub Desktop.
Doing Thangs
public static class DispatcherHelper
{
public static void DelayInvoke(this Dispatcher dispatcher, TimeSpan ts, Action action)
{
DispatcherTimer delayTimer = new DispatcherTimer();
delayTimer.Interval = ts;
delayTimer.Tick += (s, e) =>
{
delayTimer.Stop();
action();
};
delayTimer.Start();
}
}
// Using it:
// Over 1.5s duration with a 25ms step function
for(int i=0; i < 1500; i += 25) {
Dispatcher.DelayInvoke(TimeSpan.FromMilliseconds(i), //animate at from i ms until next animation (at i+25)
new Action(() =>
{
// your R,G,B will be determined to be the linear progression from your colour to white
// over 1500/25 (60) steps. There's like a billion ways to do this, just google a bit and you'll figure it out
yourLabel.ForegroundColor = new SolidColorBrush(Color.FromArgb(100, R, G, B));
}));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment