Click here to Skip to main content
15,897,291 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.4K   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/client/2007"
  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.TreeViewSelectionSample">
    <StackPanel>
        <!-- TreeView and TreeViewItem Events -->
        <ContentControl Content="SelectedItem and SelectedValue" Style="{StaticResource Header}" />
        <StackPanel>
            <TextBlock Text="TreeView.SelectedItem" Style="{StaticResource ApiName}" />
            <TextBlock Style="{StaticResource ApiDescription}">
                The selected object in the TreeView, or null if no item is
                selected.
            </TextBlock>

            <TextBlock Text="TreeView.SelectedValuePath" Style="{StaticResource ApiName}" />
            <TextBlock Style="{StaticResource ApiDescription}">
                A string that contains the path that is used to get the
                SelectedValue.
            </TextBlock>

            <TextBlock Text="TreeView.SelectedValue" Style="{StaticResource ApiName}" />
            <TextBlock Style="{StaticResource ApiDescription}">
                Gets the object that is at the specified SelectedValuePath of
                the SelectedItem, or null if no item is selected.
            </TextBlock>
        </StackPanel>

        <!-- Selection example -->
        <ContentControl Content="Selection" Style="{StaticResource Header}" />
        <TextBlock Style="{StaticResource Information}">
            Change the selection to see the SelectedItem and SelectedValue.
        </TextBlock>
        <controls:TreeView
          x:Name="TreeOfLife"
          SelectedItemChanged="OnSelectedItemChanged"
          SelectedValuePath="Classification"
          Margin="5">
            <controls:TreeView.ItemTemplate>
                <controls:HierarchicalDataTemplate ItemsSource="{Binding Subclasses}">
                    <StackPanel>
                        <TextBlock Text="{Binding Rank}" FontSize="8" FontStyle="Italic" Foreground="Gray" Margin="0 0 0 -5" />
                        <TextBlock Text="{Binding Classification}" />
                    </StackPanel>
                </controls:HierarchicalDataTemplate>
            </controls:TreeView.ItemTemplate>
        </controls:TreeView>
        <Grid HorizontalAlignment="Left">
            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <TextBlock Text="SelectedItem:" Style="{StaticResource Information}" VerticalAlignment="Center" />
            <ContentControl x:Name="SelectedItem" FontWeight="Bold" Grid.Column="1" VerticalAlignment="Center" />
            <TextBlock Grid.Row="1" Text="SelectedValue:" Style="{StaticResource Information}" VerticalAlignment="Center" />
            <ContentControl x:Name="SelectedValue" FontWeight="Bold" Grid.Row="1" Grid.Column="1" VerticalAlignment="Center" />
        </Grid>

        <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="TreeViewSelectionSample.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/client/2007"
  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.TreeViewSelectionSample"&gt;
    &lt;StackPanel&gt;
        &lt;!-- TreeView and TreeViewItem Events --&gt;
        &lt;ContentControl Content="SelectedItem and SelectedValue" Style="{StaticResource Header}" /&gt;
        &lt;StackPanel&gt;
            &lt;TextBlock Text="TreeView.SelectedItem" Style="{StaticResource ApiName}" /&gt;
            &lt;TextBlock Style="{StaticResource ApiDescription}"&gt;
                The selected object in the TreeView, or null if no item is
                selected.
            &lt;/TextBlock&gt;

            &lt;TextBlock Text="TreeView.SelectedValuePath" Style="{StaticResource ApiName}" /&gt;
            &lt;TextBlock Style="{StaticResource ApiDescription}"&gt;
                A string that contains the path that is used to get the
                SelectedValue.
            &lt;/TextBlock&gt;

            &lt;TextBlock Text="TreeView.SelectedValue" Style="{StaticResource ApiName}" /&gt;
            &lt;TextBlock Style="{StaticResource ApiDescription}"&gt;
                Gets the object that is at the specified SelectedValuePath of
                the SelectedItem, or null if no item is selected.
            &lt;/TextBlock&gt;
        &lt;/StackPanel&gt;

        &lt;!-- Selection example --&gt;
        &lt;ContentControl Content="Selection" Style="{StaticResource Header}" /&gt;
        &lt;TextBlock Style="{StaticResource Information}"&gt;
            Change the selection to see the SelectedItem and SelectedValue.
        &lt;/TextBlock&gt;
        &lt;controls:TreeView
          x:Name="TreeOfLife"
          SelectedItemChanged="OnSelectedItemChanged"
          SelectedValuePath="Classification"
          Margin="5"&gt;
            &lt;controls:TreeView.ItemTemplate&gt;
                &lt;controls:HierarchicalDataTemplate ItemsSource="{Binding Subclasses}"&gt;
                    &lt;StackPanel&gt;
                        &lt;TextBlock Text="{Binding Rank}" FontSize="8" FontStyle="Italic" Foreground="Gray" Margin="0 0 0 -5" /&gt;
                        &lt;TextBlock Text="{Binding Classification}" /&gt;
                    &lt;/StackPanel&gt;
                &lt;/controls:HierarchicalDataTemplate&gt;
            &lt;/controls:TreeView.ItemTemplate&gt;
        &lt;/controls:TreeView&gt;
        &lt;Grid HorizontalAlignment="Left"&gt;
            &lt;Grid.RowDefinitions&gt;
                &lt;RowDefinition /&gt;
                &lt;RowDefinition /&gt;
            &lt;/Grid.RowDefinitions&gt;
            &lt;Grid.ColumnDefinitions&gt;
                &lt;ColumnDefinition /&gt;
                &lt;ColumnDefinition /&gt;
            &lt;/Grid.ColumnDefinitions&gt;
            &lt;TextBlock Text="SelectedItem:" Style="{StaticResource Information}" VerticalAlignment="Center" /&gt;
            &lt;ContentControl x:Name="SelectedItem" FontWeight="Bold" Grid.Column="1" VerticalAlignment="Center" /&gt;
            &lt;TextBlock Grid.Row="1" Text="SelectedValue:" Style="{StaticResource Information}" VerticalAlignment="Center" /&gt;
            &lt;ContentControl x:Name="SelectedValue" FontWeight="Bold" Grid.Row="1" Grid.Column="1" VerticalAlignment="Center" /&gt;
        &lt;/Grid&gt;
    &lt;/StackPanel&gt;
&lt;/UserControl&gt;</sys:String>
    </src:SourceFile.Source>
  </src:SourceFile>
  <src:SourceFile Path="TreeViewSelectionSample.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;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Windows;
using System.Windows.Controls;
using System.ComponentModel;

namespace Microsoft.Windows.Controls.Samples
{
    /// &lt;summary&gt;
    /// Sample demonstrating TreeView selection.
    /// &lt;/summary&gt;
    [Sample("(2)Selection", DifficultyLevel.Basic)]
    [Category("TreeView")]
    public partial class TreeViewSelectionSample : UserControl
    {
        /// &lt;summary&gt;
        /// Initializes a new instance of the TreeViewSelectionSample class.
        /// &lt;/summary&gt;
        public TreeViewSelectionSample()
        {
            InitializeComponent();

            // Fill the tree with data
            TreeOfLife.ItemsSource = Taxonomy.Life;
        }

        /// &lt;summary&gt;
        /// Handle the TreeView.SelectedItemChanged event.
        /// &lt;/summary&gt;
        /// &lt;param name="sender"&gt;The TreeView.&lt;/param&gt;
        /// &lt;param name="e"&gt;Event arguments.&lt;/param&gt;
        [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "The event handler is declared in XAML.")]
        private void OnSelectedItemChanged(object sender, RoutedPropertyChangedEventArgs&lt;object&gt; e)
        {
            TreeView view = sender as TreeView;
            SelectedItem.Content = view.SelectedItem;
            SelectedValue.Content = view.SelectedValue;
        }
    }
}</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