Reputation:
I have a storyboard that runs forever with autoreverse for lets say 10 seconds.
Is there anyway I can get the storyboard itself to raise an event every 2 seconds along the storyboard timeline.
the storyboard only exists in c# code (not xaml).
I hope that this is enough to go on, but, if more information is needed please ask and I will explain what i am doing.
thanks in advance
Dan.
Upvotes: 0
Views: 375
Reputation: 31403
There are a couple of events provided by the storyboard timeline which may help... something like :
private Storyboard stb = new Storyboard();
private TimeSpan tsp = new TimeSpan();
public MainWindow()
{
InitializeComponent();
stb.CurrentTimeInvalidated += new EventHandler(doSomething);
}
private void doSomething(Object sender, EventArgs e)
{
Clock storyboardClock = (Clock)sender;
// or whatever other logic you want
if (storyboardClock.CurrentTime.Value.Seconds % 2 == 0 &&
Math.Abs((storyboardClock.CurrentTime.Value - tsp).TotalSeconds) >= 2)
{
// or something like this...
tsp = storyboardClock.CurrentTime.Value
- new TimeSpan(0,0,0,0,storyboardClock.CurrentTime.Value.Milliseconds);
// do something
}
}
Check out :
MSDN - CurrentStateInvalidated
Upvotes: 2