how can i make this code run synchronously?
private void slide_anim1(int from, int to, string direction)
{
Duration d = new Duration(new TimeSpan(0, 0, 0, 0, 300));
Storyboard sb = new Storyboard();
DoubleAnimation da1, da2;
if (direction == "in")
{
da1 = new DoubleAnimation(from, to, d);
da2 = new DoubleAnimation(1, 0, d);
da1.EasingFunction = da2.EasingFunction = new SineEase();
Storyboard.SetTargetProperty(da1, new PropertyPath("(Canvas.Top)"));
Storyboard.SetTargetProperty(da2, new PropertyPath("(Opacity)"));
}
else {
da1 = new DoubleAnimation(from, to, d);
da2 = new DoubleAnimation(0, 1, d);
da1.EasingFunction = da2.EasingFunction = new BackEase();
Storyboard.SetTargetProperty(da1, new PropertyPath("(Canvas.Top)"));
Storyboard.SetTargetProperty(da2, new PropertyPath("(Opacity)"));
}
sb.Children.Add(da1);
sb.Children.Add(da2);
Storyboard.SetTarget(sb, main_grid);
sb.Begin();
}I can't use the .Completed event in my context, because the function that usesslide_anim1 has to return something only, but ONLY, when the animation finishes.