<UserControl x:Class="TradeBlotter.Views.GainLossView"
						 xmlns:vw="clr-namespace:TradeBlotter.Views"								 
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:d3="http://research.microsoft.com/DynamicDataDisplay/1.0" 
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:dc="clr-namespace:TradeBlotter.UIUtils"
             xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
						 xmlns:local="clr-namespace:TradeBlotter.UIUtils"			
             xmlns:wpfx="http://schemas.xceed.com/wpf/xaml/toolkit"
             mc:Ignorable="d" 
             d:DesignHeight="400" d:DesignWidth="1024">
  <wpfx:BusyIndicator Name="BusyBar" IsBusy="{Binding Path=BusyIndicator}" BusyContent="{Binding Path=BusyContent}" >
    <Grid Background="LightGray">
    <DockPanel>
      <Grid Margin="4">
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="Auto" />
          <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
          <RowDefinition Height="10*" />
          <RowDefinition Height="*" />
        </Grid.RowDefinitions>
					<StackPanel Grid.Row="0" Grid.Column="0" Orientation="Vertical">
						<Label Content="Account" HorizontalAlignment="Left" Target="{Binding ElementName=accountListLbl}" ></Label>
						<wpfx:CheckComboBox ItemsSource="{Binding Path=Accounts, Mode=OneTime}" MaxWidth="100" SelectedValue="{Binding Path=SelectedAccounts, ValidatesOnDataErrors=True}" Validation.ErrorTemplate="{x:Null}" ></wpfx:CheckComboBox>
						<StackPanel Orientation="Horizontal">
							<CheckBox Content="Suspend Update" IsChecked="{Binding Path=CheckBoxSuspendUpdate,Mode=TwoWay}" HorizontalAlignment="Left"  />
						</StackPanel>
						<Label Content="Symbols" HorizontalAlignment="Left" Target="{Binding ElementName=symbolListLbl}" ></Label>
						<ComboBox ItemsSource="{Binding Path=Symbols, Mode=TwoWay}" SelectedItem="{Binding Path=SelectedSymbol, ValidatesOnDataErrors=True}" Validation.ErrorTemplate="{x:Null}" >
							<ComboBox.ItemsPanel>
								<ItemsPanelTemplate>
									<VirtualizingStackPanel/>
								</ItemsPanelTemplate>
							</ComboBox.ItemsPanel>
						</ComboBox>
						<Button Margin="0,2" Content="{Binding Path=PercentButtonText}" HorizontalAlignment="Left" Command="{Binding Path=ToggleReturnOrPercentCommand}"></Button>
						<Button Margin="0,2" Content="{Binding Path=ActiveTotalButtonText}" HorizontalAlignment="Left" Command="{Binding Path=ToggleActiveOrTotalCommand}"></Button>
						<Button Margin="0,2" Content="Refresh" HorizontalAlignment="Left" Command="{Binding Path=RefreshCommand}"></Button>
						<CheckBox Content="Legend Visible" IsChecked="{Binding Path=CheckBoxLegendVisible}" Grid.ColumnSpan="3" Grid.Row="5" Height="16" HorizontalAlignment="Left" Margin="5,6,0,0" VerticalAlignment="Top" />
						<CheckBox Content="Least Squares Fit" IsChecked="{Binding Mode=TwoWay,Path=LeastSquaresFit}" Grid.ColumnSpan="3" Grid.Row="7" Height="16" HorizontalAlignment="Left" Margin="5,6,0,0" VerticalAlignment="Top" />
						<CheckBox Content="Include Dividends" IsChecked="{Binding Mode=TwoWay,Path=CheckBoxIncludeDividends}" Grid.ColumnSpan="3" Grid.Row="9" Height="16" HorizontalAlignment="Left" Margin="5,6,0,0" VerticalAlignment="Top" />
            <CheckBox Content="Cumulative Returns" IsChecked="{Binding Mode=TwoWay,Path=CheckBoxUseCumulativeReturns}" Grid.ColumnSpan="3" Grid.Row="10" Height="16" HorizontalAlignment="Left" Margin="5,6,0,0" VerticalAlignment="Top" />
          </StackPanel>
				<Grid Grid.Column="1" Grid.RowSpan="2" >
        <Grid.RowDefinitions>
          <RowDefinition Height=".7*" />
          <RowDefinition Height="2" />
          <RowDefinition Height=".5*" />
        </Grid.RowDefinitions>
					<GridSplitter Background="LightBlue" ResizeDirection="Rows" Grid.Column="1" Grid.ColumnSpan="1" Grid.Row="1" Width="Auto" Height="5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0"/>
					<Border CornerRadius="6" BorderBrush="WhiteSmoke" Background="LightGray" BorderThickness="2" Padding="8">
						<d3:ChartPlotter Background="WhiteSmoke" Grid.Row="0" Name="gainLoss" Margin="10,10,20,10" dc:ChartPlotterLegendBehavior.LegendVisibleProperty="{Binding Path=LegendVisible}" LegendVisibility="Hidden" d3:Viewport2D.UsesApproximateContentBoundsComparison="False" BorderThickness="0">
							<d3:ChartPlotter.MainHorizontalAxis>
								<d3:HorizontalDateTimeAxis Name="dateAxis"/>
							</d3:ChartPlotter.MainHorizontalAxis>
							<d3:ChartPlotter.MainVerticalAxis>
								<d3:VerticalAxis Name="countAxis"/>
							</d3:ChartPlotter.MainVerticalAxis>
							<d3:LineGraph d3:NewLegend.Description="Gain/Loss" d3:Viewport2D.UsesApproximateContentBoundsComparison="False" x:Name="Data" DataSource="{Binding Path=Data}" Stroke="MidnightBlue" StrokeThickness="2"/>
							<d3:LineGraph d3:NewLegend.Description="MA21" x:Name="MA21" DataSource="{Binding Path=MA21}" Stroke="Green" StrokeThickness="2" />
							<d3:LineGraph d3:NewLegend.Description="MA55" x:Name="MA55" DataSource="{Binding Path=MA55}" Stroke="LimeGreen" StrokeThickness="2" />
							<d3:LineGraph d3:NewLegend.Description="MA90" x:Name="MA90" DataSource="{Binding Path=MA90}" Stroke="LightGreen" StrokeThickness="2" />
							<d3:LineGraph x:Name="LeastSquares" d3:NewLegend.Description="{Binding Path=LeastSquaresTitle}" DataSource="{Binding LeastSquares}" Stroke="Orange" StrokeThickness="2"/>
							<d3:CursorCoordinateGraph Name="cursorGraph" dc:CoordinateGraphBehavior.XTextMappingProperty="MM/dd/yyyy" LineStrokeThickness="1"/>
							<d3:Header FontFamily="Arial" Content="{Binding Path=Title}"/>
							<d3:VerticalAxisTitle FontFamily="Arial" Content="Gain/Loss"/>
							<d3:HorizontalAxisTitle FontFamily="Arial" Content="Date" />
						</d3:ChartPlotter>
					</Border>
					<Grid Grid.Row="2" Grid.Column="1" >
							<Grid.ColumnDefinitions>
								<ColumnDefinition Width="7*" />
								<ColumnDefinition Width="3" />
								<ColumnDefinition Width="7*" />
							</Grid.ColumnDefinitions>
							<Grid.RowDefinitions>
								<RowDefinition Height="*" />
							</Grid.RowDefinitions>
							<telerik:RadGridView Background="WhiteSmoke" Grid.Row="0" Grid.Column="0" SelectedItem="{Binding SelectedGainLossCompoundItem, Mode=TwoWay}" ItemsSource="{Binding Path=GainLossCompoundModelCollection, ValidatesOnDataErrors=False,Mode=OneWay}" CanUserSelect="True"  SelectionMode="Single" AlternationCount="2" AlternateRowBackground="Bisque" ShowGroupFooters="True" ShowColumnFooters="True" AutoGenerateColumns="False" Margin="0,3,0.5,-3" >
					    <telerik:RadGridView.Columns>
								<telerik:GridViewDataColumn IsReadOnly="True" Header="Date" DataMemberBinding="{Binding Path=Date,StringFormat='{}{0:MM/dd/yyyy}'}" />
								<telerik:GridViewDataColumn IsReadOnly="True" Header="Exposure" DataMemberBinding="{Binding Path=ActiveExposure,StringFormat='{}{0:C}'}" />
								<telerik:GridViewDataColumn IsReadOnly="True" Header="Dividends" IsVisible="{Binding Path=CheckBoxIncludeDividends}" DataMemberBinding="{Binding Path=TotalDividendsPaid,StringFormat='{}{0:C}'}" />										
								<telerik:GridViewDataColumn IsReadOnly="True" Header="Active G/L" DataMemberBinding="{Binding Path=ActiveGainLoss,StringFormat='{}{0:C}'}" />
								<telerik:GridViewDataColumn IsReadOnly="True" Header="Active G/L(%)" DataMemberBinding="{Binding Path=ActiveGainLossPercent,StringFormat='{}{0:N3}'}" />					
								<telerik:GridViewDataColumn IsReadOnly="True" Header="Total G/L" DataMemberBinding="{Binding Path=TotalGainLoss,StringFormat='{}{0:C}'}" />
								<telerik:GridViewDataColumn IsReadOnly="True" Header="Total G/L(%)" DataMemberBinding="{Binding Path=TotalGainLossPercent,StringFormat='{}{0:N3}'}" />					
							</telerik:RadGridView.Columns>
					</telerik:RadGridView>
							<telerik:RadGridView Background="WhiteSmoke" Grid.Row="0" Grid.Column="2" SelectedItem="{Binding SelectedGainLossSummaryItem, Mode=TwoWay}" ItemsSource="{Binding Path=GainLossSummaryItemCollection, ValidatesOnDataErrors=False,Mode=OneWay}" CanUserSelect="True"  SelectionMode="Single" AlternationCount="2" AlternateRowBackground="Bisque" ShowGroupFooters="True" ShowColumnFooters="True" AutoGenerateColumns="False" Margin="0,3,0.5,-3" >
							<telerik:RadContextMenu.ContextMenu>
								<telerik:RadContextMenu x:Name="GridContextMenu" StaysOpen="False" ItemsSource="{Binding MenuItems}">
									<telerik:RadContextMenu.ItemContainerStyle>
										<Style TargetType="telerik:RadMenuItem">
											<Setter Property="Header" Value="{Binding Text}" />
											<Setter Property="Command" Value="{Binding MenuItemClickedCommand}" />
											<Setter Property="StaysOpenOnClick" Value="False" />
										</Style>
									</telerik:RadContextMenu.ItemContainerStyle>
								</telerik:RadContextMenu>
							</telerik:RadContextMenu.ContextMenu>
							<telerik:RadGridView.Columns>
							<telerik:GridViewDataColumn IsReadOnly="True" Header="Date" DataMemberBinding="{Binding Path=Date,StringFormat='{}{0:MM/dd/yyyy}'}" />
              <telerik:GridViewDataColumn IsReadOnly="True" Header="Symbol" DataMemberBinding="{Binding Path=Symbol}" >
								<telerik:GridViewDataColumn.AggregateFunctions>
									<local:GainLossViewSumFunctionSymbol />
								</telerik:GridViewDataColumn.AggregateFunctions>
								<telerik:GridViewColumn.ToolTipTemplate>
									<DataTemplate >
										<StackPanel Orientation="Horizontal" >
											<TextBlock Background="LemonChiffon" MaxWidth="1000" TextWrapping="Wrap" Text="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type vw:GainLossView}},Path=DataContext.Parity}"/>
										</StackPanel>
									</DataTemplate>
								</telerik:GridViewColumn.ToolTipTemplate>									
							</telerik:GridViewDataColumn>								
							<telerik:GridViewDataColumn IsReadOnly="True" Header="Current G/L" DataMemberBinding="{Binding Path=CurrentGainLoss,StringFormat='{}{0:C}'}" >
								<telerik:GridViewDataColumn.AggregateFunctions>
								  <telerik:SumFunction ResultFormatString="{}{0:C}" />
								</telerik:GridViewDataColumn.AggregateFunctions>
							</telerik:GridViewDataColumn>
							<telerik:GridViewDataColumn IsReadOnly="True" Header="Previous G/L" DataMemberBinding="{Binding Path=PreviousGainLoss,StringFormat='{}{0:C}'}" />

						  <telerik:GridViewDataColumn IsReadOnly="True" Header="$ Change(%)" DataMemberBinding="{Binding Path=ChangePercent,StringFormat='{}{0:N3}'}" >
								<telerik:GridViewColumn.ToolTipTemplate>
									<DataTemplate >
										<StackPanel Orientation="Horizontal" >
											<TextBlock Background="LemonChiffon" MaxWidth="1000" TextWrapping="Wrap" Text="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type vw:GainLossView}},Path=DataContext.DollarChangePercent}"/>
										</StackPanel>
									</DataTemplate>
								</telerik:GridViewColumn.ToolTipTemplate>									
							</telerik:GridViewDataColumn>									

							<telerik:GridViewDataColumn IsReadOnly="True" Header="$ Change" DataMemberBinding="{Binding Path=Change,StringFormat='{}{0:C}'}" >
								<telerik:GridViewDataColumn.AggregateFunctions>
								  <telerik:SumFunction ResultFormatString="{}{0:C}" />
								</telerik:GridViewDataColumn.AggregateFunctions>
							</telerik:GridViewDataColumn>
						</telerik:RadGridView.Columns>
					</telerik:RadGridView>
							<GridSplitter Background="LightBlue" ResizeDirection="Columns" Grid.Column="1" Grid.ColumnSpan="1" Grid.Row="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0"/>
						</Grid>
				</Grid>
				</Grid>
			</DockPanel>
		</Grid>
	</wpfx:BusyIndicator>
</UserControl>
