Click here to Skip to main content
15,891,375 members
Articles / Desktop Programming / WPF

How to create stock charts using the Silverlight Toolkit

Rate me:
Please Sign up or sign in to vote.
4.70/5 (15 votes)
16 Feb 2009CPOL2 min read 142.2K   2.7K   65  
An article on how to create a Candlestick stock chart using the Silverlight Toolkit.
// (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 Microsoft.Windows.Controls.DataVisualization
{
    /// <summary>
    /// Represents a storyboard queue that plays storyboards in sequence.
    /// </summary>
    internal class StoryboardQueue
    {
        /// <summary>
        /// A queue of the storyboards.
        /// </summary>
        private Queue<Storyboard> _storyBoards = new Queue<Storyboard>();

        /// <summary>
        /// Accepts a new storyboard to play in sequence.
        /// </summary>
        /// <param name="storyBoard">The storyboard to play.</param>
        public void Enqueue(Storyboard storyBoard)
        {
            Enqueue(storyBoard, null);
        }

        /// <summary>
        /// Accepts a new storyboard to play in sequence.
        /// </summary>
        /// <param name="storyBoard">The storyboard to play.</param>
        /// <param name="completedAction">An action to execute when the 
        /// storyboard completes.</param>
        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();
            }
        }

        /// <summary>
        /// Removes the next storyboard in the queue and plays it.
        /// </summary>
        private void Dequeue()
        {
            if (_storyBoards.Count > 0)
            {
                _storyBoards.Peek().Begin();
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
South Africa South Africa
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions