Click here to Skip to main content
15,881,644 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.
-->

<UserControl
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
  xmlns:samples="clr-namespace:Microsoft.Windows.Controls.Samples"
  x:Class="Microsoft.Windows.Controls.Samples.DefaultThemeSample">
    <StackPanel>
        <ContentControl Content="Default Theme" Style="{StaticResource Header}" />
        <samples:AllControls />
        <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="DefaultThemeSample.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:samples="clr-namespace:Microsoft.Windows.Controls.Samples"
  x:Class="Microsoft.Windows.Controls.Samples.DefaultThemeSample"&gt;
    &lt;StackPanel&gt;
        &lt;ContentControl Content="Default Theme" Style="{StaticResource Header}" /&gt;
        &lt;samples:AllControls /&gt;
    &lt;/StackPanel&gt;
&lt;/UserControl&gt;</sys:String>
    </src:SourceFile.Source>
  </src:SourceFile>
  <src:SourceFile Path="DefaultThemeSample.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.Windows.Controls;

namespace Microsoft.Windows.Controls.Samples
{
    /// &lt;summary&gt;
    /// Demonstrate the default theme.
    /// &lt;/summary&gt;
    [Sample("Theming/Themes/Default")]
    public partial class DefaultThemeSample : UserControl
    {
        /// &lt;summary&gt;
        /// Initializes a new instance of the DefaultThemeSample class.
        /// &lt;/summary&gt;
        public DefaultThemeSample()
        {
            InitializeComponent();
        }
    }
}</sys:String>
    </src:SourceFile.Source>
  </src:SourceFile>
  <src:SourceFile Path="AllControls.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 x:Class="Microsoft.Windows.Controls.Samples.AllControls"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:basics="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
  xmlns:controls="clr-namespace:Microsoft.Windows.Controls;assembly=Microsoft.Windows.Controls"
  xmlns:input="clr-namespace:Microsoft.Windows.Controls;assembly=Microsoft.Windows.Controls.Input"
  xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
  xmlns:clr="clr-namespace:System;assembly=mscorlib"
  xmlns:primitives="clr-namespace:System.Windows.Controls.Primitives;assembly=System.Windows.Controls"
  xmlns:dataprimitives="clr-namespace:System.Windows.Controls.Primitives;assembly=System.Windows.Controls.Data"
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows"
  xmlns:charting="clr-namespace:Microsoft.Windows.Controls.DataVisualization.Charting;assembly=Microsoft.Windows.Controls.DataVisualization"
  xmlns:datavis="clr-namespace:Microsoft.Windows.Controls.DataVisualization;assembly=Microsoft.Windows.Controls.DataVisualization"
  xmlns:sys="clr-namespace:System;assembly=mscorlib"
  xmlns:local="clr-namespace:Microsoft.Windows.Controls.Samples"
  mc:Ignorable="d"&gt;
    &lt;UserControl.Resources&gt;
        
       &lt;local:VacationBudgetCollection x:Key="VacationBudget"/&gt;

        &lt;controls:HierarchicalDataTemplate x:Key="MediaEntry"&gt;
            &lt;StackPanel Orientation="Horizontal"&gt;
                &lt;TextBlock FontWeight="Bold" Text="{Binding Path=MediaName}" /&gt;
            &lt;/StackPanel&gt;
        &lt;/controls:HierarchicalDataTemplate&gt;

        &lt;controls:HierarchicalDataTemplate x:Key="Catalog" ItemsSource="{Binding Path=MediaItems}" ItemTemplate="{StaticResource MediaEntry}"&gt;
            &lt;StackPanel Orientation="Horizontal"&gt;
                &lt;TextBlock FontWeight="Bold" Text="{Binding Path=CatalogName}" /&gt;
            &lt;/StackPanel&gt;
        &lt;/controls:HierarchicalDataTemplate&gt;
    &lt;/UserControl.Resources&gt;

    &lt;Grid x:Name="Root" Height="Auto" Width="Auto" Background="#FF595959" Opacity="1"&gt;
        &lt;controls:DockPanel Opacity="1" HorizontalAlignment="Left" VerticalAlignment="Stretch"&gt;
            &lt;controls:Expander Header="Microsoft Communities" ExpandDirection="Down" VerticalAlignment="Stretch" controls:DockPanel.Dock="Top" Background="#FF858585" Margin="0,0,0,0"&gt;
                &lt;StackPanel Orientation="Horizontal"&gt;
                    &lt;Image x:Name="ExpanderImage" Margin="10,10,10,10"&gt;&lt;/Image&gt;
                    &lt;TextBlock Text="Welcome to Silverlight Themes" FontSize="20" Margin="40,0,0,0" HorizontalAlignment="Center" VerticalAlignment="Center"&gt;&lt;/TextBlock&gt;
                &lt;/StackPanel&gt;
            &lt;/controls:Expander&gt;

            &lt;StackPanel controls:DockPanel.Dock="Bottom" Orientation="Horizontal" Background="DarkGray" HorizontalAlignment="Stretch" Margin="0,42,0,0" VerticalAlignment="Bottom"&gt;
                &lt;controls:Label Content="Connecting to server..." HorizontalContentAlignment="Right"&gt;&lt;/controls:Label&gt;
                &lt;ProgressBar IsIndeterminate="True" Width="300" HorizontalContentAlignment="Right"&gt;&lt;/ProgressBar&gt;
            &lt;/StackPanel&gt;

            &lt;Grid controls:DockPanel.Dock="Right" Margin="0,10,10,0"&gt;
                &lt;Grid.RowDefinitions&gt;
                    &lt;RowDefinition Height="Auto"/&gt;
                    &lt;RowDefinition Height="Auto"/&gt;
                    &lt;RowDefinition Height="Auto"/&gt;
                &lt;/Grid.RowDefinitions&gt;
                &lt;Grid Margin="5,2,5,0"  VerticalAlignment="Stretch" Grid.Row="0"&gt;
                    &lt;StackPanel Margin="0,0,0,0"&gt;
                        &lt;controls:Label Content="My Trips Bar" FontWeight="Bold" FontFamily="Portable User Interface" Height="16" Width="179" HorizontalAlignment="Left" /&gt;
                        &lt;basics:Calendar Height="168" Width="179" /&gt;
                    &lt;/StackPanel&gt;
                &lt;/Grid&gt;
                &lt;Border Grid.Row="0" Background="#FF6A6A6A" Opacity="0.42" CornerRadius="5,5,5,5" Canvas.ZIndex="-1" Grid.RowSpan="3" /&gt;

                &lt;Grid Grid.Row="2" Grid.RowSpan="2" Margin="0,16,0,0"&gt;
                    &lt;Grid.RowDefinitions&gt;
                        &lt;RowDefinition Height="Auto" /&gt;
                        &lt;RowDefinition Height="Auto" /&gt;
                    &lt;/Grid.RowDefinitions&gt;
                    &lt;Button Content="Scheduled Trips" IsEnabled="False" /&gt;
                    &lt;ListBox x:Name="TripsList" Grid.RowSpan="2" Grid.Row="1" Height="300" /&gt;
                &lt;/Grid&gt;

                &lt;Grid Height="Auto" VerticalAlignment="Top" Grid.Row="1" Margin="5,27,5,10"&gt;
                    &lt;Grid.ColumnDefinitions&gt;
                        &lt;ColumnDefinition Width="0.614*" /&gt;
                        &lt;ColumnDefinition Width="0.386*" /&gt;
                    &lt;/Grid.ColumnDefinitions&gt;
                    &lt;Grid.RowDefinitions&gt;
                        &lt;RowDefinition Height="Auto" /&gt;
                        &lt;RowDefinition Height="0.5*" /&gt;
                        &lt;RowDefinition Height="0.5*" /&gt;
                    &lt;/Grid.RowDefinitions&gt;

                    &lt;controls:Label Content="Add New Trip" FontWeight="Bold" FontFamily="Portable User Interface" Height="16" Width="179" VerticalAlignment="Stretch" /&gt;
                    &lt;Button Height="Auto" Content="Add" VerticalAlignment="Stretch" Grid.RowSpan="2" Grid.Row="1" Grid.Column="1" Margin="5,0,0,0" Padding="18,3,16,3" /&gt;
                    &lt;TextBox Height="Auto" Grid.Row="1" VerticalAlignment="Stretch" Text="TextBox" TextWrapping="Wrap" Margin="0,0,0,0" /&gt;
                    &lt;basics:DatePicker Grid.Row="2" /&gt;
                &lt;/Grid&gt;
            &lt;/Grid&gt;

            &lt;Grid controls:DockPanel.Dock="Left"  VerticalAlignment="Stretch" Margin="10,5,0,0"&gt;
           
                &lt;Grid.RowDefinitions&gt;
                    &lt;RowDefinition /&gt;
                    &lt;RowDefinition /&gt;
                    &lt;RowDefinition /&gt;
                &lt;/Grid.RowDefinitions&gt;

                &lt;controls:TreeView ItemTemplate="{StaticResource Catalog}" x:Name="VactionTreeView" SelectedItemChanged="OnVacationChanged" Margin="0,0,0,0" Opacity="1" Background="{x:Null}" Width="350" Height="250" VerticalAlignment="Top" /&gt;
                &lt;Border Margin="0,0,0,0" Opacity="0.415" Background="#FF8C8484" CornerRadius="5,5,5,5" Canvas.ZIndex="-1" Width="350" Height="250" VerticalAlignment="Stretch"/&gt;

                &lt;Grid Grid.Row="1" Margin="0,6,0,0" Height="Auto"&gt;
                    &lt;Grid.RowDefinitions&gt;
                        &lt;RowDefinition /&gt;

                    &lt;/Grid.RowDefinitions&gt;

                    &lt;StackPanel Margin="7,5,0,0" Height="Auto"&gt;
                        &lt;controls:Label Content="Printing" FontFamily="Portable User Interface" FontWeight="Bold" HorizontalAlignment="Left" /&gt;

                        &lt;RadioButton Content="All"/&gt;
                        &lt;RadioButton Content="Selection"/&gt;
                        &lt;RadioButton Content="Current"/&gt;
                    &lt;/StackPanel&gt;

                    &lt;StackPanel HorizontalAlignment="Right" Margin="0,5,7,7" Width="Auto" Grid.Column="1"&gt;
                        &lt;controls:Label Content="Copies" FontFamily="Portable User Interface" FontWeight="Bold" Height="Auto" Width="Auto" /&gt;
                        &lt;StackPanel Height="Auto" Width="Auto" Orientation="Horizontal" &gt;
                            &lt;controls:Label Content="Number of Copies:" FontFamily="Portable User Interface" FontWeight="Normal" Height="16" Width="104" /&gt;
                            &lt;input:NumericUpDown /&gt;
                        &lt;/StackPanel&gt;
                        &lt;ComboBox HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Height="25" SelectedIndex="0" Margin="0,7,0,0"&gt;
                            &lt;ComboBoxItem Content="Black&amp;amp;White"&gt;&lt;/ComboBoxItem&gt;
                            &lt;ComboBoxItem Content="Color"&gt;&lt;/ComboBoxItem&gt;
                            &lt;ComboBoxItem Content="Draft"&gt;&lt;/ComboBoxItem&gt;
                        &lt;/ComboBox&gt;
                        &lt;CheckBox Height="Auto" Width="Auto" Content="Collate" Margin="0,15,0,0" /&gt;
                    &lt;/StackPanel&gt;
                    &lt;Border Background="#FF979797" Canvas.ZIndex="-1" Opacity="0.44" CornerRadius="5,5,5,5" /&gt;
                &lt;/Grid&gt;
                &lt;basics:TabControl x:Name="ChartTabControl" Width="350" Height="270" Grid.Row="2" Margin="0,11,0,0" VerticalAlignment="Top"&gt;
                    &lt;basics:TabItem Header="Budget"&gt;
                       &lt;charting:Chart Title="Vacation Budget" VerticalAlignment="Stretch" &gt;
                            &lt;charting:Chart.Series&gt;
                                &lt;charting:PieSeries
                                        IndependentValueBinding="{Binding ExpenseType}"
                                        DependentValueBinding="{Binding ExpenseValue}" IsSelectionEnabled="True"&gt;
                                        &lt;charting:PieSeries.ItemsSource&gt;
                                        &lt;controls:ObjectCollection&gt;
                                            &lt;local:Budget ExpenseType="Air Fair" ExpenseValue="150"/&gt;
                                            &lt;local:Budget ExpenseType="Hotels" ExpenseValue="60"/&gt;
                                            &lt;local:Budget ExpenseType="Food" ExpenseValue="20"/&gt;
                                            &lt;local:Budget ExpenseType="Entertainment" ExpenseValue="30"/&gt;
                                        &lt;/controls:ObjectCollection&gt;
                                &lt;/charting:PieSeries.ItemsSource&gt;
                             &lt;/charting:PieSeries&gt;
                           &lt;/charting:Chart.Series&gt;
                        &lt;/charting:Chart&gt;
                    &lt;/basics:TabItem&gt;
                    &lt;basics:TabItem Header="Entertaiment"&gt;
                        &lt;charting:Chart Title="Entertainment Budget 2007-2008" Width="350" Height="240" LegendTitle="Legend" VerticalAlignment="Stretch"&gt;
                            &lt;charting:Chart.Series&gt;
                                &lt;charting:ColumnSeries Title="Budget 2007" 
                                      IndependentValueBinding="{Binding ExpenseType}"
                                      DependentValueBinding="{Binding ExpenseValue}" IsSelectionEnabled="True"&gt;
                                        &lt;charting:ColumnSeries.ItemsSource&gt;
                                            &lt;controls:ObjectCollection&gt;
                                                &lt;local:Budget ExpenseType="Movies" ExpenseValue="150"/&gt;
                                                &lt;local:Budget ExpenseType="Museum" ExpenseValue="60"/&gt;
                                            &lt;/controls:ObjectCollection&gt;
                                        &lt;/charting:ColumnSeries.ItemsSource&gt;
                                &lt;/charting:ColumnSeries&gt;
                                &lt;charting:ColumnSeries Title="Buget 2008"
                                      IndependentValueBinding="{Binding ExpenseType}"
                                      DependentValueBinding="{Binding ExpenseValue}" IsSelectionEnabled="True"&gt;
                                        &lt;charting:ColumnSeries.ItemsSource&gt;
                                            &lt;controls:ObjectCollection&gt;
                                                &lt;local:Budget ExpenseType="Movies" ExpenseValue="200"/&gt;
                                                &lt;local:Budget ExpenseType="Museum" ExpenseValue="140"/&gt;
                                            &lt;/controls:ObjectCollection&gt;
                                        &lt;/charting:ColumnSeries.ItemsSource&gt;
                                &lt;/charting:ColumnSeries&gt;
                            &lt;/charting:Chart.Series&gt;
                        &lt;/charting:Chart&gt;
                    &lt;/basics:TabItem&gt;
                    &lt;basics:TabItem Header="Trends"&gt;
                        &lt;charting:Chart Width="350" Height="240" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" LegendTitle="Legend" Title="Budget Trends in 2007"&gt;
                            &lt;charting:Chart.Series&gt;
                                &lt;charting:LineSeries Title="Trends"
                                ItemsSource="{StaticResource VacationBudget}"
                                IndependentValueBinding="{Binding Date}"
                                DependentValueBinding="{Binding ExpenseValue}"&gt;     
                                &lt;/charting:LineSeries&gt;
                            &lt;/charting:Chart.Series&gt;
                             &lt;charting:Chart.Axes&gt;
                                &lt;charting:Axis Orientation="Horizontal" AxisType="DateTime" MaxHeight="1" Opacity="0" Minimum="2008/07/07" Maximum="2008/09/08"/&gt;
                                &lt;charting:Axis Orientation="Vertical" AxisType="Linear" MaxWidth="1" Opacity="0" Minimum="36" Maximum="55"/&gt;
                            &lt;/charting:Chart.Axes&gt;
                        &lt;/charting:Chart&gt;
                    &lt;/basics:TabItem&gt;
                &lt;/basics:TabControl&gt;
            &lt;/Grid&gt;

            &lt;Grid Height="Auto" Width="Auto" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="30,0,30,0"&gt;
                &lt;Grid.RowDefinitions&gt;
                    &lt;RowDefinition Height="0.622*"/&gt;
                    &lt;RowDefinition Height="0.378*"/&gt;
                &lt;/Grid.RowDefinitions&gt;

                &lt;Grid Margin="0,5,0,0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"&gt;
                    &lt;Grid.ColumnDefinitions&gt;
                        &lt;ColumnDefinition Width="Auto"/&gt;
                        &lt;ColumnDefinition Width="*"/&gt;
                    &lt;/Grid.ColumnDefinitions&gt;
                    &lt;Grid.RowDefinitions&gt;
                        &lt;RowDefinition Height="Auto"/&gt;
                        &lt;RowDefinition Height="0.756*"/&gt;
                        &lt;RowDefinition Height="Auto" MinHeight="45"/&gt;
                    &lt;/Grid.RowDefinitions&gt;

                    &lt;Border Background="#FF8E8D8D" CornerRadius="5,5,5,5"&gt;
                        &lt;Image x:Name="VacationImage" Width="400" Height="300" Stretch="UniformToFill" /&gt;         
                    &lt;/Border&gt;
                    &lt;Slider HorizontalAlignment="Center" Width="Auto" Grid.Column="1" Grid.Row="0" IsDirectionReversed="False" Orientation="Vertical" Margin="5,0,0,0" /&gt;
                    &lt;Slider Grid.Row="2" VerticalAlignment="Top" Height="Auto" Margin="0,5,0,0" /&gt;
                &lt;/Grid&gt;

                &lt;Grid Grid.Row="1" Margin="0,10,0,0"&gt;
                    &lt;Grid.RowDefinitions&gt;
                        &lt;RowDefinition Height="Auto"&gt;&lt;/RowDefinition&gt;
                        &lt;RowDefinition Height="*"&gt;&lt;/RowDefinition&gt;
                    &lt;/Grid.RowDefinitions&gt;
                    &lt;StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,10,10,0" VerticalAlignment="Top"&gt;
                        &lt;controls:Label Content="Search" VerticalAlignment="Bottom" Margin="0,0,4,0" /&gt;
                        &lt;controls:AutoCompleteBox x:Name="SampleAutoComplete" Width="300" /&gt;
                    &lt;/StackPanel&gt;
                    &lt;data:DataGrid Grid.Row="1" x:Name="SampleDataGrid" Margin="10,10,10,10" HorizontalAlignment="Stretch" Width="Auto" Height="Auto" VerticalAlignment="Top"/&gt;
                    &lt;Border Height="280" HorizontalAlignment="Stretch" Margin="0,0,0,0" VerticalAlignment="Top" Width="Auto" Grid.Row="0" Grid.RowSpan="2" Background="#FF666666" CornerRadius="5,5,5,5" Canvas.ZIndex="-1" Opacity="0.3" /&gt;
                &lt;/Grid&gt;
            &lt;/Grid&gt;
        &lt;/controls:DockPanel&gt;
        &lt;Border CornerRadius="10,10,10,10" Opacity="0" Canvas.ZIndex="-1" HorizontalAlignment="Stretch" Width="Auto" Height="Auto"&gt;
            &lt;Border.Background&gt;
                &lt;LinearGradientBrush EndPoint="0.256,0.834" StartPoint="0.964,-0.021"&gt;
                    &lt;GradientStop Color="#FF000000" /&gt;
                    &lt;GradientStop Color="#FDFFFFFF" Offset="1" /&gt;
                &lt;/LinearGradientBrush&gt;
            &lt;/Border.Background&gt;
            &lt;Canvas&gt;
                &lt;Path Stretch="Fill" Data="F1 M 4.33333,342L 3.00001,342.667C 38.4239,316.358 73.8478,290.05 115.514,276.495C 157.181,262.939 205.091,262.136 221.355,249.222C 237.62,236.307 222.239,211.281 216.964,196.869C 211.688,182.457 216.518,178.66 220.752,175.335C 224.987,172.011 228.625,169.159 236.123,170.46C 243.62,171.761 254.977,177.214 258.157,174.734C 261.337,172.255 256.341,161.843 255.656,155.23C 254.972,148.616 258.6,145.801 272.987,150.229C 287.374,154.657 312.52,166.329 323.224,158.176C 333.927,150.024 330.187,122.048 342.072,98.74C 353.958,75.4324 381.468,56.7934 408.2,42.9915C 434.933,29.1896 460.888,20.2247 479.177,24.1753C 497.465,28.1258 508.087,44.9917 516.113,62.7541C 524.139,80.5164 529.57,99.1753 535,117.834C 497.667,199.333 503,156.667 498.333,205.333C 496.62,223.201 492.301,230.285 489.07,232.788C 491.562,233.109 495.396,234.163 501,236.667C 532.333,250.667 540.333,266.667 562.333,244.667C 584.333,222.667 555.667,167.333 597.667,226C 639.667,284.667 590.333,346 577,352C 570.333,367.333 530.333,375.333 530.333,375.333C 530.333,375.333 427,410.667 433,389.333C 422.333,397.333 399,326 401,314.667C 403,303.333 415,285.333 415,285.333L 425.667,248.667L 422.333,234.667L 413.667,228C 357.667,224 321,237.333 323.667,254.667C 326.333,272 319.667,272 329.667,294.667C 339.667,317.333 405,316 344.333,362.667C 283.667,409.333 232.333,574 5.66667,489.333L 4.33333,342 Z M 145.333,311.333C 127.476,311.333 113,325.81 113,343.667C 113,361.524 127.476,376 145.333,376C 163.19,376 177.667,361.524 177.667,343.667C 177.667,325.81 163.19,311.333 145.333,311.333 Z M 203.667,292.667C 191.516,292.667 181.667,302.517 181.667,314.667C 181.667,326.817 191.516,336.667 203.667,336.667C 215.817,336.667 225.667,326.817 225.667,314.667C 225.667,302.517 215.817,292.667 203.667,292.667 Z M 246.667,279.333C 239.487,279.333 233.667,284.258 233.667,290.333C 233.667,296.408 239.487,301.333 246.667,301.333C 253.846,301.333 259.667,296.408 259.667,290.333C 259.667,284.258 253.846,279.333 246.667,279.333 Z M 567.667,270C 559.566,270 553,276.417 553,284.333C 553,292.249 559.566,298.667 567.667,298.667C 575.767,298.667 582.333,292.249 582.333,284.333C 582.333,276.417 575.767,270 567.667,270 Z " d:LayoutOverrides="Width, Height" Opacity="0.6" VerticalAlignment="Stretch" d:IsHidden="True"&gt;
                    &lt;Path.Fill&gt;
                        &lt;LinearGradientBrush StartPoint="-7.80076e-010,0.495068" EndPoint="1.04155,0.495068"&gt;
                            &lt;GradientStop Color="#FF000000" Offset="0" /&gt;
                            &lt;GradientStop Color="#FFFFFFFF" Offset="1" /&gt;
                        &lt;/LinearGradientBrush&gt;
                    &lt;/Path.Fill&gt;
                &lt;/Path&gt;
            &lt;/Canvas&gt;
        &lt;/Border&gt;
    &lt;/Grid&gt;
&lt;/UserControl&gt;</sys:String>
    </src:SourceFile.Source>
  </src:SourceFile>
  <src:SourceFile Path="AllControls.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.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using Microsoft.Windows.Controls.Theming;
using System.Collections.Generic;
using Microsoft.Windows.Controls.DataVisualization.Charting;
using System.Collections;
using System.Linq;

namespace Microsoft.Windows.Controls.Samples
{
    /// &lt;summary&gt;
    /// A user control with examples of every control to demonstrate themes.
    /// &lt;/summary&gt;
    public partial class AllControls : UserControl
    {
        /// &lt;summary&gt;
        /// Gets or sets the Background Brush for this user Control.
        /// &lt;/summary&gt;
        public Brush PreferredBackground
        {
            get { return Root.Background; }
            set { Root.Background = value; }
        }

        /// &lt;summary&gt;
        /// Initializes a new instance of the AllControls class.
        /// &lt;/summary&gt;
        public AllControls()
        {
            InitializeComponent();
            LayoutUpdated += OnLayoutUpdated;

            SampleDataGrid.ItemsSource = Employee.Executives;
            SampleAutoComplete.ItemsSource = Catalog.VacationMediaItems;
            TripsList.ItemsSource = Catalog.PlannedVacationMediaItems;
            VacationImage.Source = Catalog.VacationCatalog.CatalogImage.Source;

            VactionTreeView.LayoutUpdated += OnTreeViewLayoutUpdated;
            ObjectCollection collection = new ObjectCollection();
            collection.Add(Catalog.VacationCatalog);
            VactionTreeView.ItemsSource = collection;

            ExpanderImage.Source = SharedResources.GetImage("SilverlightThemesLogo.jpg").Source;

            System.Windows.Threading.DispatcherTimer myDispatcherTimer = new System.Windows.Threading.DispatcherTimer();
            myDispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 4000);  
            myDispatcherTimer.Tick += new EventHandler(OnTick);
            myDispatcherTimer.Start();
        }

        /// &lt;summary&gt;
        /// Represents the current tab.
        /// &lt;/summary&gt;
        private int _currentTab;

        /// &lt;summary&gt;
        /// Fires every 4 miliseconds while the DispatcherTimer is active.
        /// &lt;/summary&gt;
        /// &lt;param name="sender"&gt;The source object.&lt;/param&gt;
        /// &lt;param name="e"&gt;Event arguments.&lt;/param&gt;
        private void OnTick(object sender, EventArgs e)
        {
            _currentTab = (_currentTab + 1) % ChartTabControl.Items.Count;
            ChartTabControl.SelectedIndex = _currentTab;       
        }

        /// &lt;summary&gt;
        /// Initialize ImplicitStyleManager once the visual tree is ready.
        /// &lt;/summary&gt;
        /// &lt;param name="sender"&gt;The UserControl.&lt;/param&gt;
        /// &lt;param name="e"&gt;Event arguments.&lt;/param&gt;
        private void OnLayoutUpdated(object sender, EventArgs e)
        {
            // Only apply once
            LayoutUpdated -= OnLayoutUpdated;

            // ImplicitStyleManager is design to only style controls in the
            // namescope it was defined in.  Since user controls create new
            // namescopes, the ImplicitStyleManager acting on the Theme controls
            // will not style the controls in the AllControls user control.  By
            // applying ImplicitStyleManager to the root of the user control
            // (without giving it a theme to use), it will walk up the visual
            // tree to the Theme control and use its styles.
            ImplicitStyleManager.SetApplyMode(Root, ImplicitStylesApplyMode.Auto);
            ImplicitStyleManager.Apply(Root);
        }

        /// &lt;summary&gt;
        /// Expanding the TreeView Items.
        /// &lt;/summary&gt;
        /// &lt;param name="sender"&gt;The source object.&lt;/param&gt;
        /// &lt;param name="e"&gt;The event arguments.&lt;/param&gt;
        private void OnTreeViewLayoutUpdated(object sender, EventArgs e)
        {
            VactionTreeView.LayoutUpdated -= OnTreeViewLayoutUpdated;
            VactionTreeView.ExpandAll();
        }

        /// &lt;summary&gt;
        /// Fired when selected item in the tree changes.
        /// &lt;/summary&gt;
        /// &lt;param name="sender"&gt;The source object.&lt;/param&gt;
        /// &lt;param name="e"&gt;The selection changed event data.&lt;/param&gt;
        [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Declared as an event handler in XAML.")]
        private void OnVacationChanged(object sender, RoutedPropertyChangedEventArgs&lt;object&gt; e)
        {
            MediaItem media = VactionTreeView.SelectedItem as MediaItem;
            if (media != null)
            {
                VacationImage.Source = media.Image.Source;
            }
            else
            {
                Catalog catalog = VactionTreeView.SelectedItem as Catalog;
                if (catalog != null)
                {
                    VacationImage.Source = catalog.CatalogImage.Source;
                }
            }
        }
    }
}</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