How to Wait for a RoutedEvent? Since there is no definition for GetAwaiter i can't use the await keyword. So how should i modify the Code so that it waits for completion of the GIF Animation?
The Code who calls the RoutedEvent:
public static async Task<Boolean> Draw(List<Point> points, int counter, Polyline current, Color color, MainWindow main)
{
current.Stroke = new SolidColorBrush(color);
current.Points.Clear();
for (int i = 0; i < points.Count; i++)
{
await Task.Delay(TimeSpan.FromMilliseconds(1));
current.Points.Add(points[i]);
if(i == points.Count - 1)
{
var completed = new XamlAnimatedGif.AnimationCompletedEventArgs(current);
await ShowExplosion(main, current.Points.ElementAt(i));
}
}
points.Clear();
current = null;
return true;
}
an the RoutedEvent:
static RoutedEvent ShowExplosion(MainWindow main, Point coordinate)
{
Image explosion = new Image();
explosion.Width = 40;
explosion.Height = 40;
Canvas.SetLeft(explosion, coordinate.X - 20);
Canvas.SetTop(explosion, coordinate.Y - 20);
//Relative URI
var resourcePath = new Uri("pack://application:,,,/Resources/GIF/Explosion2_trsp.gif");
XamlAnimatedGif.AnimationBehavior.SetSourceUri(explosion, resourcePath);
XamlAnimatedGif.AnimationBehavior.SetRepeatBehavior(explosion, new System.Windows.Media.Animation.RepeatBehavior(1));
XamlAnimatedGif.AnimationBehavior.SetAutoStart(explosion, true);
main.canvas_shots.Children.Add(explosion);
return XamlAnimatedGif.AnimationBehavior.AnimationCompletedEvent;
}