Click here to Skip to main content
15,896,557 members
Articles / DevOps / Testing

Composite Application Reloaded

Rate me:
Please Sign up or sign in to vote.
4.88/5 (38 votes)
11 May 2011CPOL12 min read 118.5K   1.5K   95  
A much simpler composite application library.
<UserControl 
	x:Name="posViewRoot"
	x:Class="StockTraderRI.Modules.Position.PositionSummary.PositionSummaryView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:Converters="clr-namespace:StockTraderRI.Infrastructure.Converters;assembly=StockTraderRI.Infrastructure"
	xmlns:a="http://schemas.galador.net/xaml/libraries"
	>
    <UserControl.Resources>
        <Converters:CurrencyConverter x:Key="currencyConverter" />
        <Converters:PercentConverter x:Key="percentConverter" />
        <Converters:DecimalToColorConverter x:Key="decimalToColorConverter" />
        <DataTemplate x:Key="GainLossTemplate">
            <TextBlock Text="{Binding Converter={StaticResource percentConverter}, Path=GainLossPercent}" 
                                     Foreground="{Binding Converter={StaticResource decimalToColorConverter}, Path=GainLossPercent}" />
        </DataTemplate>
    </UserControl.Resources>
    <ListView BorderThickness="0" Width="Auto"
                  ItemsSource="{Binding Path=Position.Items}" 
                  SelectedItem="{Binding Path=CurrentPositionSummaryItem, Mode=TwoWay}"  AlternationCount="2"
                  IsSynchronizedWithCurrentItem="True" AutomationProperties.AutomationId="PositionSummaryGrid">
        <ListView.View>
            <GridView AllowsColumnReorder="true" ColumnHeaderToolTip="Current positions"
                          >
                <GridViewColumn Header="Symbol" 
            		DisplayMemberBinding="{Binding Path=TickerSymbol}" 
            		Width="65"/>
                <GridViewColumn Header="Shares"  
                  DisplayMemberBinding="{Binding Path=Shares}"
                  Width="65" />
                <GridViewColumn Header="Last"  
                  DisplayMemberBinding="{Binding Converter={StaticResource currencyConverter}, Path=CurrentPrice}"
                  Width="65" />
                <GridViewColumn Header="Cost Basis"  
                  DisplayMemberBinding="{Binding Converter={StaticResource currencyConverter}, Path=CostBasis}"
                  Width="85" />
                <GridViewColumn Header="Market Value"  
                  DisplayMemberBinding="{Binding Converter={StaticResource currencyConverter}, Path=MarketValue}"
                  Width="85" />
                <GridViewColumn Header="Gain/Loss %" DisplayMemberBinding="{Binding Converter={StaticResource percentConverter}, Path=GainLossPercent}"  CellTemplate="{StaticResource GainLossTemplate}" Width="85" />
                <GridViewColumn Header="Actions">
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition  Width="47"/>
                                    <ColumnDefinition  Width="47"/>
                                </Grid.ColumnDefinitions>

								<Button Grid.Column="0" Command="{Binding DataContext.BuyCommand, ElementName=posViewRoot}" CommandParameter="{Binding Path=TickerSymbol}" AutomationProperties.AutomationId="ActionsBuyButton" Template="{StaticResource AddButtonTemplate}"  Cursor="Hand" Width="30" />
								<Button Grid.Column="1" Command="{Binding DataContext.SellCommand, ElementName=posViewRoot}" CommandParameter="{Binding Path=TickerSymbol}" AutomationProperties.AutomationId="ActionsSellButton" Template="{StaticResource RemoveButtonTemplate}" Cursor="Hand"  Width="30"/>

                            </Grid>
                            
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>
            </GridView>
        </ListView.View>
		<ListView.ItemTemplate>
			<DataTemplate>
				<a:DataControl Data="{Binding}"/>
			</DataTemplate>
		</ListView.ItemTemplate>
    </ListView>
</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
Software Developer (Senior) http://www.ansibleww.com.au
Australia Australia
The Australia born French man who went back to Australia later in life...
Finally got over life long (and mostly hopeless usually, yay!) chronic sicknesses.
Worked in Sydney, Brisbane, Darwin, Billinudgel, Darwin and Melbourne.

Comments and Discussions