Click here to Skip to main content
15,881,812 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 141.9K   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.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace Microsoft.Windows.Controls.Samples
{
    /// <summary>
    /// A wrapper type that can be used for visually displaying reflected type 
    /// information.
    /// </summary>
    public class MemberInfoData
    {
        /// <summary>
        /// Gets an enumerable set of PME information objects.
        /// </summary>
        /// <param name="type">The type to reflect over.</param>
        /// <returns>Returns the set of MemberInfoData objects.</returns>
        public static IEnumerable<MemberInfoData> GetSetForType(Type type)
        {
            MemberInfo[] members = type.GetMembers();
            if (members.Length > 0)
            {
                foreach (MemberInfo member in members)
                {
                    if (member.Name.Contains("get_") || member.Name.Contains("set_") || member.Name.Contains("add_") || member.Name.Contains("remove_"))
                    {
                        continue;
                    }

                    MemberInfoData pme = new MemberInfoData(member);
                    yield return pme;
                }
            }
            else
            {
                yield break;
            }
        }

        /// <summary>
        /// Initializes a new instance of the MemberInfoData class 
        /// with the provided MemberInfo object's data.
        /// </summary>
        /// <param name="mi">The member info object.</param>
        public MemberInfoData(MemberInfo mi)
        {
            MemberInfo = mi;
            Name = mi.Name;

            if (mi is PropertyInfo)
            {
                IconName = "Property.png";
            }

            MethodInfo methodInfo = mi as MethodInfo;
            if (methodInfo != null)
            {
                IconName = methodInfo.IsStatic ? "Static.png" : "Method.png";
            }

            if (mi is EventInfo)
            {
                IconName = "Event.png";
            }

            FieldInfo field = mi as FieldInfo;
            if (field != null)
            {
                IconName = "Static.png";
            }
        }

        /// <summary>
        /// Gets the member information object.
        /// </summary>
        public MemberInfo MemberInfo { get; private set; }

        /// <summary>
        /// Gets or sets the icon string name.
        /// </summary>
        private string IconName { get; set; }

        /// <summary>
        /// Gets the icon.
        /// </summary>
        public Image Icon
        {
            get
            {
                return IconName == null ? null : SharedResources.GetIcon(IconName);
            }
        }

        /// <summary>
        /// Gets or sets the name.
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// Gets the foreground color based on method properties.
        /// </summary>
        public Brush ForegroundColor
        {
            get
            {
                Color c = MemberInfo.DeclaringType == MemberInfo.ReflectedType ? Colors.Black : Colors.DarkGray;
                return new SolidColorBrush(c);
            }
        }

        /// <summary>
        /// Overrides the ToString method to display the name.
        /// </summary>
        /// <returns>Returns the name as a string.</returns>
        public override string ToString()
        {
            return Name;
        }
    }
}

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