// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.
using System;
using System.Collections.Generic;
using System.Windows.Media.Animation;
namespace System.Windows.Controls.DataVisualization
{
///
/// Represents a storyboard queue that plays storyboards in sequence.
///
internal class StoryboardQueue
{
///
/// A queue of the storyboards.
///
private Queue _storyBoards = new Queue();
///
/// Accepts a new storyboard to play in sequence.
///
/// The storyboard to play.
/// An action to execute when the
/// storyboard completes.
public void Enqueue(Storyboard storyBoard, EventHandler completedAction)
{
storyBoard.Completed +=
(sender, args) =>
{
if (completedAction != null)
{
completedAction(sender, args);
}
_storyBoards.Dequeue();
Dequeue();
};
_storyBoards.Enqueue(storyBoard);
if (_storyBoards.Count == 1)
{
Dequeue();
}
}
///
/// Removes the next storyboard in the queue and plays it.
///
private void Dequeue()
{
if (_storyBoards.Count > 0)
{
Storyboard storyboard = _storyBoards.Peek();
storyboard.Begin();
}
}
}
}