Click here to Skip to main content
15,886,806 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 142K   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.
-->

<UserControl 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:controls="clr-namespace:Microsoft.Windows.Controls;assembly=Microsoft.Windows.Controls"
    xmlns:common="clr-namespace:Microsoft.Windows.Controls.Samples;assembly=Microsoft.Windows.Controls.Samples.Common"
    x:Class="Microsoft.Windows.Controls.Samples.NestedHierarchicalDataTemplateSample">
    <StackPanel>
        <StackPanel.Resources>
            <!-- HierarchicalDataTemplates -->
            <controls:HierarchicalDataTemplate x:Key="songEntry">
                <StackPanel Orientation="Horizontal">                    
                    <ContentPresenter Margin="0 0 4 0" Content="{Binding Icon}" />
                    <TextBlock FontStyle="Italic" Text="{Binding Path=Title}" />                    
                </StackPanel>
            </controls:HierarchicalDataTemplate>

            <controls:HierarchicalDataTemplate x:Key="albumEntry" ItemsSource="{Binding Path=Songs}" ItemTemplate="{StaticResource songEntry}">
                <StackPanel Orientation="Horizontal">                    
                    <ContentPresenter Margin="0 0 4 0" Content="{Binding Icon}" />
                    <TextBlock Text="{Binding Path=Title}" />                    
                </StackPanel>
            </controls:HierarchicalDataTemplate>

            <controls:HierarchicalDataTemplate x:Key="artistEntry" ItemsSource="{Binding Path=Albums}" ItemTemplate="{StaticResource albumEntry}">
                <StackPanel Orientation="Horizontal">                                        
                    <ContentPresenter Margin="0 0 4 0" Content="{Binding Icon}" />
                    <TextBlock FontWeight="Bold" Text="{Binding Path=ArtistName}" />
                </StackPanel>
            </controls:HierarchicalDataTemplate>
        </StackPanel.Resources>

        <ContentControl Content="Nesting HierarchicalDataTemplates" Style="{StaticResource Header}" />
        <TextBlock Style="{StaticResource Information}">
            This shows how to nest HierarchicalDataTemplates for when you want 
            each level of your tree to have its own DataTemplate and associated styling.
        </TextBlock>

        <controls:TreeView x:Name="ArtistTree" ItemTemplate="{StaticResource artistEntry}" />

        <src:SourceViewer xmlns:src="clr-namespace:Microsoft.Windows.Controls.Samples;assembly=Microsoft.Windows.Controls.Samples.Common" xmlns:sys="clr-namespace:System;assembly=mscorlib">
  <src:SourceFile Path="NestedHierarchicalDataTemplateSample.xaml">
    <src:SourceFile.Source>
      <sys:String>&lt;!--
// (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.
--&gt;

&lt;UserControl 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:controls="clr-namespace:Microsoft.Windows.Controls;assembly=Microsoft.Windows.Controls"
    xmlns:common="clr-namespace:Microsoft.Windows.Controls.Samples;assembly=Microsoft.Windows.Controls.Samples.Common"
    x:Class="Microsoft.Windows.Controls.Samples.NestedHierarchicalDataTemplateSample"&gt;
    &lt;StackPanel&gt;
        &lt;StackPanel.Resources&gt;
            &lt;!-- HierarchicalDataTemplates --&gt;
            &lt;controls:HierarchicalDataTemplate x:Key="songEntry"&gt;
                &lt;StackPanel Orientation="Horizontal"&gt;                    
                    &lt;ContentPresenter Margin="0 0 4 0" Content="{Binding Icon}" /&gt;
                    &lt;TextBlock FontStyle="Italic" Text="{Binding Path=Title}" /&gt;                    
                &lt;/StackPanel&gt;
            &lt;/controls:HierarchicalDataTemplate&gt;

            &lt;controls:HierarchicalDataTemplate x:Key="albumEntry" ItemsSource="{Binding Path=Songs}" ItemTemplate="{StaticResource songEntry}"&gt;
                &lt;StackPanel Orientation="Horizontal"&gt;                    
                    &lt;ContentPresenter Margin="0 0 4 0" Content="{Binding Icon}" /&gt;
                    &lt;TextBlock Text="{Binding Path=Title}" /&gt;                    
                &lt;/StackPanel&gt;
            &lt;/controls:HierarchicalDataTemplate&gt;

            &lt;controls:HierarchicalDataTemplate x:Key="artistEntry" ItemsSource="{Binding Path=Albums}" ItemTemplate="{StaticResource albumEntry}"&gt;
                &lt;StackPanel Orientation="Horizontal"&gt;                                        
                    &lt;ContentPresenter Margin="0 0 4 0" Content="{Binding Icon}" /&gt;
                    &lt;TextBlock FontWeight="Bold" Text="{Binding Path=ArtistName}" /&gt;
                &lt;/StackPanel&gt;
            &lt;/controls:HierarchicalDataTemplate&gt;
        &lt;/StackPanel.Resources&gt;

        &lt;ContentControl Content="Nesting HierarchicalDataTemplates" Style="{StaticResource Header}" /&gt;
        &lt;TextBlock Style="{StaticResource Information}"&gt;
            This shows how to nest HierarchicalDataTemplates for when you want 
            each level of your tree to have its own DataTemplate and associated styling.
        &lt;/TextBlock&gt;

        &lt;controls:TreeView x:Name="ArtistTree" ItemTemplate="{StaticResource artistEntry}" /&gt;
    &lt;/StackPanel&gt;

&lt;/UserControl&gt;</sys:String>
    </src:SourceFile.Source>
  </src:SourceFile>
  <src:SourceFile Path="NestedHierarchicalDataTemplateSample.xaml.cs">
    <src:SourceFile.Source>
      <sys:String>// (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.Windows.Controls;
using System.ComponentModel;

namespace Microsoft.Windows.Controls.Samples
{
    /// &lt;summary&gt;
    /// The NestedHierarchicalDataTemplate sample page shows how to nest
    /// HierarchicalDataTemplate templates with each HierarchicalDataTemplate
    /// having its own unique template.
    /// &lt;/summary&gt;
    [Sample("Nested HierarchicalDataTemplate", DifficultyLevel.Scenario)]
    [Category("TreeView")]
    public partial class NestedHierarchicalDataTemplateSample : UserControl
    {
        /// &lt;summary&gt;
        /// Initializes a new instance of the
        /// NestedHierarchicalDataTemplateSample class.
        /// &lt;/summary&gt;
        public NestedHierarchicalDataTemplateSample()
        {
            InitializeComponent();
            ArtistTree.ItemsSource = Artist.AllArtists;
        }
    }
}</sys:String>
    </src:SourceFile.Source>
  </src:SourceFile>
</src:SourceViewer>
    </StackPanel>

</UserControl>

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