Click here to Skip to main content
15,892,005 members
Articles / Mobile Apps / Windows Phone 7

XAMLFinance – A Cross-platform WPF, Silverlight & WP7 Application

Rate me:
Please Sign up or sign in to vote.
4.94/5 (99 votes)
21 Sep 2011CPOL27 min read 217.6K   9.9K   251  
This article describes the development of XAML Finance, a cross-platform application which works on the desktop, using Windows Presentation Foundation (WPF), on the web, using Silverlight and on Windows Phone 7 (WP7).
<phone:PhoneApplicationPage 
    x:Class="XAMLFinance.PanoramaIndex"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:conv="clr-namespace:XAMLFinance.View.Converter"
    xmlns:ctrl="clr-namespace:XAMLFinance.Controls"
    xmlns:jumpList="clr-namespace:WP7Contrib.View.Controls.JumpList;assembly=WP7Contrib.View.Controls"
    xmlns:behaviours="clr-namespace:WP7Contrib.View.Controls.Behaviors;assembly=WP7Contrib.View.Controls"
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
    xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows"
    xmlns:view="clr-namespace:XAMLFinance.View"
    xmlns:tree="clr-namespace:System.Windows.Controls.DataVisualization;assembly=TreeMapWP7"
    xmlns:vis="clr-namespace:Visiblox.Charts;assembly=Visiblox.Charts"
    xmlns:tk="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="800"
    d:DataContext="{d:DesignData Source=../../Common/XAMLFinanceApp/View/XAMLFinanceDesignData.xml}"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait"  Orientation="Portrait"
    shell:SystemTray.IsVisible="False">

  <phone:PhoneApplicationPage.Resources>
    <conv:StringFormatConverter x:Key="StringFormatter"/>
    <conv:PriceChangeConverter x:Key="PriceChangeConverter"/>
    <conv:NumericSignToVisibilityConverter x:Key="NumericSignToVisibilityConverter"/>

    <Style TargetType="Line" x:Key="GridLineStyle">
      <Setter Property="Stroke" Value="#333"/>
    </Style>
    
    <DataTemplate x:Key="PriceTileTemplate">
      <Button Width="160" Height="160"
              Margin="10"
              Style="{StaticResource FlashButtonStyle}"
              Click="FavouriteButton_Click">
        <i:Interaction.Behaviors>
          <behaviours:TiltBehaviour/>
        </i:Interaction.Behaviors>
        <Grid>
          <Rectangle Fill="{Binding Change, Converter={StaticResource PriceChangeConverter}}"
                     Opacity="0.5"/>

          <view:DirecationIndicator
                      Opacity="0.2"
                      DataContext="{Binding Path=Change}"
                      Height="100" Width="100"
                      HorizontalAlignment="Right"
                      VerticalAlignment="Bottom"
                      Margin="10"/>
          <TextBlock Text="{Binding Mid}"
                     FontSize="40"
                     VerticalAlignment="Center"                   
                     HorizontalAlignment="Center"/>
          <TextBlock Text="{Binding Symbol}"
                     FontSize="35"
                     Margin="5"
                     VerticalAlignment="Top"                   
                     HorizontalAlignment="Left"/>
        </Grid>
      </Button>
    </DataTemplate>

    <DataTemplate x:Key="PriceTileTemplateSmall">
      <Button Width="120" Height="120"
              Margin="5"
              Style="{StaticResource FlashButtonStyle}"
              Click="FavouriteButton_Click">
        <i:Interaction.Behaviors>
          <behaviours:TiltBehaviour/>
        </i:Interaction.Behaviors>
        <Grid>
          <Rectangle Fill="{Binding Change, Converter={StaticResource PriceChangeConverter}}"
                     Opacity="0.5"/>

          <view:DirecationIndicator
                      Opacity="0.2"
                      DataContext="{Binding Path=Change}"
                      Height="70" Width="70"
                      HorizontalAlignment="Right"
                      VerticalAlignment="Bottom"
                      Margin="10"/>
          <TextBlock FontSize="25"
                     VerticalAlignment="Center"                   
                     HorizontalAlignment="Center">
            <TextBlock.Text>
              <Binding Path="ChangePercent"
                      Converter="{StaticResource StringFormatter}"
                      ConverterParameter=" {0:N2}%"/>
            </TextBlock.Text>
          </TextBlock>
          <TextBlock Text="{Binding Symbol}"
                     FontSize="25"
                     Margin="5"
                     VerticalAlignment="Top"                   
                     HorizontalAlignment="Left"/>
        </Grid>
      </Button>
    </DataTemplate>

  </phone:PhoneApplicationPage.Resources>

  <!--LayoutRoot contains the root grid where all other page content is placed-->
  <Grid x:Name="LayoutRoot">

    <Grid.RowDefinitions>
      <RowDefinition Height="130"/>
      <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    
    <controls:Panorama Grid.RowSpan="2">
      <i:Interaction.Behaviors>
        <behaviours:PanoramaOpacityBehaviour Opacity="0.5"/>
      </i:Interaction.Behaviors>
      <controls:Panorama.Title>
        <TextBlock Text="XAML Finance"
                   FontSize="100" Margin="0,50,0,0"/>
      </controls:Panorama.Title>
      <controls:Panorama.Background>
        <ImageBrush ImageSource="wall-street-sign.jpg"
                    x:Name="BackgroundImage"
                    Opacity="0"/>
      </controls:Panorama.Background>

      <controls:PanoramaItem Header="Favourites"
                             Orientation="Horizontal">
        <Grid MaxWidth="800">
          <ItemsControl ItemsSource="{Binding Favourites}"
            ItemTemplate="{StaticResource PriceTileTemplate}">
            <ItemsControl.ItemsPanel>
              <ItemsPanelTemplate>
                <tk:WrapPanel Orientation="Horizontal"/>
              </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
          </ItemsControl>
        </Grid>
      </controls:PanoramaItem>

      <controls:PanoramaItem Header="Stocks">
        <Grid>
          <jumpList:JumpList x:Name="jumpList"
                       ItemsSource="{Binding Path=Pricelist.Prices}"
                       ScrollDuration="0"
                       SelectionChanged="JumpList_SelectionChanged">

            <jumpList:JumpList.ItemTemplate>
              <DataTemplate>
                <Grid Height="70" Width="480"
                  DataContext="{Binding PriceViewModel}">
                  <Grid Margin="7">
                    <Grid HorizontalAlignment="Right" VerticalAlignment="Center"
                                  Margin="0,3,160,0">
                      <Path Height="16" Width="16" Fill="White"
                                  Visibility="{Binding Path=Change, Converter={StaticResource NumericSignToVisibilityConverter}}"
                                  Stretch="Uniform"                                  
                                  Data="m0,0 l5,0 l-2.5,-5 z"/>
                      <Path Height="16" Width="16" Fill="White"
                                  Visibility="{Binding Path=Change, Converter={StaticResource NumericSignToVisibilityConverter}, ConverterParameter=1}"
                                  Stretch="Uniform"                                   
                                  Data="m0,0 l5,0 l-2.5,5 z"/>
                    </Grid>
                    <TextBlock Text="{Binding Symbol}"
                                       FontSize="{StaticResource PhoneFontSizeLarge}"
                                       VerticalAlignment="Top"
                                       HorizontalAlignment="Left"/>
                    <TextBlock Text="{Binding Instrument}"
                                       Width="280" 
                                       FontSize="{StaticResource PhoneFontSizeSmall}"
                                       VerticalAlignment="Bottom"
                                       Foreground="DarkGray"
                                       HorizontalAlignment="Left"/>
                    <TextBlock HorizontalAlignment="Right"
                                       VerticalAlignment="Center"
                                       FontSize="{StaticResource PhoneFontSizeLarge}"
                                       Width="150"
                                       Text="{Binding Mid}"
                                       Foreground="{Binding Change, Converter={StaticResource PriceChangeConverter}}"/>
                  </Grid>
                </Grid>
              </DataTemplate>
            </jumpList:JumpList.ItemTemplate>

            <jumpList:JumpList.CategoryProvider>
              <jumpList:AlphabetCategoryProvider PropertyName="Symbol"/>
            </jumpList:JumpList.CategoryProvider>

            <!-- create large square jump buttons -->
            <jumpList:JumpList.JumpButtonStyle>
              <Style TargetType="Button">
                <Setter Property="HorizontalAlignment" Value="Left"/>
                <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
                <Setter Property="VerticalContentAlignment" Value="Stretch"/>
                <Setter Property="Padding" Value="0"/>
                <Setter Property="Width" Value="64"/>
                <Setter Property="Height" Value="64"/>
              </Style>
            </jumpList:JumpList.JumpButtonStyle>
          </jumpList:JumpList>
        </Grid>
      </controls:PanoramaItem>
      
      <controls:PanoramaItem Header="Heatmap">
        <Button Style="{StaticResource FlashButtonStyle}"
                Click="HeatmapButton_Click">
          <i:Interaction.Behaviors>
            <behaviours:TiltBehaviour/>
          </i:Interaction.Behaviors>
          <tree:TreeMap ItemsSource="{Binding Path=HeatMap.Sectors}"
                       Interpolators="{StaticResource colourInterpolator}">
            <tree:TreeMap.ItemDefinition>
              <tree:TreeMapItemDefinition ValueBinding="{Binding MarketCap}">
                <DataTemplate>
                  <Grid>
                    <Border x:Name="Border"
                            BorderBrush="#666"
                            BorderThickness="1"
                            Margin="1"
                            Opacity="1">                      
                    </Border>
                                        <Border CornerRadius="5"
                                Background="#99FFFFFF"
                                VerticalAlignment="Center"
                                Padding="10,0,10,0"
                                Margin="10,0,10,0"
                                HorizontalAlignment="Center">

                                            <TextBlock Text="{Binding Name}"
                                    FontSize="16"
                                    FontWeight="Bold"
                                    Opacity="1"
                                    Foreground="Black"/>

                                        </Border>
                                    </Grid>
                </DataTemplate>
              </tree:TreeMapItemDefinition>
            </tree:TreeMap.ItemDefinition>
          </tree:TreeMap>
        </Button>
      </controls:PanoramaItem>

      <controls:PanoramaItem Header="FTSE 100">
        <Grid>
          <Grid.RowDefinitions>
            <RowDefinition Height="1.6*"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition/>
            <RowDefinition Height="Auto"/>
            <RowDefinition/>
          </Grid.RowDefinitions>       
        
         <vis:Chart LegendVisibility="Collapsed"
                   DataContext="{Binding FTSE100Price}">
            <vis:Chart.XAxis>
              <vis:DateTimeAxis IsAutoMarginEnabled="False"
                              GridlineStyle="{StaticResource GridLineStyle}"/>
            </vis:Chart.XAxis>
            <vis:Chart.YAxis>
              <vis:LinearAxis GridlineStyle="{StaticResource GridLineStyle}"
                            LabelsPosition="Inside"
                              ShowMinorTicks="False"
                              ShowMajorTicks="False"/>
            </vis:Chart.YAxis>
            <vis:Chart.Series>
              <vis:LineSeries Name="LineSeries"
                            ShowArea="True">
                <vis:LineSeries.DataSeries>
                  <vis:BindableDataSeries x:Name="bindableSeries"
                                        XValueBinding="{Binding Path=Date}" 
                                        YValueBinding="{Binding Path=Price}"
                                        ItemsSource="{Binding Path=.}">
                  </vis:BindableDataSeries>
                </vis:LineSeries.DataSeries>
              </vis:LineSeries>
            </vis:Chart.Series>
          </vis:Chart>
          
          <TextBlock Text="Movers" FontSize="{StaticResource PhoneFontSizeMedium}"
                     Grid.Row="1"/>
          <ItemsControl ItemsSource="{Binding Pricelist.Movers}"
                        ItemTemplate="{StaticResource PriceTileTemplateSmall}"
                        Grid.Row="2">
            <ItemsControl.ItemsPanel>
              <ItemsPanelTemplate>
                <tk:WrapPanel Orientation="Horizontal"/>
              </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
          </ItemsControl>
          
          <TextBlock Text="Shakers" FontSize="{StaticResource PhoneFontSizeMedium}"
                     Grid.Row="3"/>
          <ItemsControl ItemsSource="{Binding Pricelist.Shakers}"
                        ItemTemplate="{StaticResource PriceTileTemplateSmall}"
                        Grid.Row="4">
            <ItemsControl.ItemsPanel>
              <ItemsPanelTemplate>
                <tk:WrapPanel Orientation="Horizontal"/>
              </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
          </ItemsControl>
        </Grid>
      </controls:PanoramaItem>
    </controls:Panorama>
    
    <Grid Background="Black"
          Grid.Row="1"
          x:Name="LoadingIndicator"
          Opacity="0">
      <TextBlock Text="Loading ..."
                 FontSize="{StaticResource PhoneFontSizeMedium}"
                 VerticalAlignment="Center"
                 Margin="40,-80,0,0"/>
      <tk:PerformanceProgressBar IsIndeterminate="True"/>      
    </Grid>
  </Grid>

</phone:PhoneApplicationPage>

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
Architect Scott Logic
United Kingdom United Kingdom
I am CTO at ShinobiControls, a team of iOS developers who are carefully crafting iOS charts, grids and controls for making your applications awesome.

I am a Technical Architect for Visiblox which have developed the world's fastest WPF / Silverlight and WP7 charts.

I am also a Technical Evangelist at Scott Logic, a provider of bespoke financial software and consultancy for the retail and investment banking, stockbroking, asset management and hedge fund communities.

Visit my blog - Colin Eberhardt's Adventures in .NET.

Follow me on Twitter - @ColinEberhardt

-

Comments and Discussions