<UserControl x:Class="TradeBlotter.Views.TradeModelView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:d3="http://research.microsoft.com/DynamicDataDisplay/1.0" 
             xmlns:dc="clr-namespace:TradeBlotter.UIUtils"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:wpfx="http://schemas.xceed.com/wpf/xaml/toolkit"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
      <Style x:Key="TradeItemStyle" TargetType="{x:Type telerik:RadGridView}">
      </Style>
    </UserControl.Resources>
    <wpfx:BusyIndicator Name="BusyBar" IsBusy="{Binding Path=BusyIndicator}" BusyContent="Running Model..">
    <Grid Background="LightGray">
    <DockPanel>
      <Grid Margin="4">
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="Auto" />
          <ColumnDefinition Width="6" />
          <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
          <RowDefinition Height="Auto" />
          <RowDefinition Height="Auto" />
          <RowDefinition Height="3" />
          <RowDefinition Height="30" />
        </Grid.RowDefinitions>
        <StackPanel Grid.Row="0" Grid.Column="0" Orientation="Vertical">
        <Label Content="Watch List" HorizontalAlignment="Left" ></Label>
        <ComboBox ItemsSource="{Binding Path=WatchListNames, Mode=OneTime}" SelectedItem="{Binding Path=SelectedWatchList, ValidatesOnDataErrors=True}" Validation.ErrorTemplate="{x:Null}" ></ComboBox>

        <!--<Label Content="Symbol" HorizontalAlignment="Left" Target="{Binding ElementName=symbolLbl}" ></Label>-->
        <Label Content="Symbol" HorizontalAlignment="Left"  ></Label>
        <ComboBox ItemsSource="{Binding Path=Symbols, Mode=OneWay}" SelectedItem="{Binding Path=SelectedSymbol, ValidatesOnDataErrors=True}" SelectedIndex="{Binding Path=SelectedSymbolIndex,Mode=TwoWay, ValidatesOnDataErrors=True}" Validation.ErrorTemplate="{x:Null}" >
				<ComboBox.ItemsPanel>
					<ItemsPanelTemplate>
						<VirtualizingStackPanel/>
					</ItemsPanelTemplate>
				</ComboBox.ItemsPanel>
				</ComboBox>

        <Label Content="Investment" HorizontalAlignment="Left" Target="{Binding ElementName=investmentLbl}" ></Label>
        <TextBox Text="{Binding Path=Investment, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}" AcceptsReturn="False" IsReadOnly="False"/>

        <Label Content="Start Date" HorizontalAlignment="Left" Target="{Binding ElementName=startDateLbl}" ></Label>
        <DatePicker HorizontalAlignment="Left" Name="startDatePck" SelectedDate="{Binding Path=SelectedStartDate, ValidatesOnDataErrors=True}" />

        <Label Content="Model" HorizontalAlignment="Left" Target="{Binding ElementName=modelLbl}" ></Label>
        <ComboBox ItemsSource="{Binding Path=Models, Mode=OneWay}" DisplayMemberPath="Value" SelectedIndex="{Binding Path=SelectedModelIndex,Mode=TwoWay, ValidatesOnDataErrors=True}" Validation.ErrorTemplate="{x:Null}" ></ComboBox>

        <Label Content="Stop Loss Threshold" HorizontalAlignment="Left" Target="{Binding ElementName=stopLossThreshholLbl}" ></Label>
        <TextBox Text="{Binding Path=StopLossThreshold, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}" AcceptsReturn="False" IsReadOnly="False"/>

        <Label Content="Stop Loss Days" HorizontalAlignment="Left" Target="{Binding ElementName=stopLossDaysLbl}" ></Label>
        <TextBox Text="{Binding Path=StopLossDays, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}" AcceptsReturn="False" IsReadOnly="False"/>

        <Button Margin="0,2" Content="Run Model" HorizontalAlignment="Left" Command="{Binding Path=RunModelCommand}"></Button>

        </StackPanel>
      </Grid>
      <Grid> 
        <Grid.RowDefinitions>
          <RowDefinition Height="3*" />
          <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <telerik:RadGridView Grid.Row="0" Grid.Column="2" Name="TradeGrid" CanUserSelect="False" ItemContainerStyle="{StaticResource TradeItemStyle}" AlternationCount="2" AlternateRowBackground="Bisque" ShowGroupFooters="True" ShowColumnFooters="True" ItemsSource="{Binding Path=TradeResults, ValidatesOnDataErrors=True}" AutoGenerateColumns="False" >
          <telerik:RadGridView.Columns>
            <telerik:GridViewDataColumn IsReadOnly="True" Header="Date" DataMemberBinding="{Binding Path=TradeDate,StringFormat='{}{0:MM/dd/yyyy}'}" />
            <telerik:GridViewDataColumn IsReadOnly="True" Header="Buy/Sell" DataMemberBinding="{Binding Path=BuySell}" />
            <telerik:GridViewDataColumn IsReadOnly="True" Header="Symbol" DataMemberBinding="{Binding Path=Symbol}" />
            <telerik:GridViewDataColumn IsReadOnly="True" Header="Shares" DataMemberBinding="{Binding Path=Shares}" />
            <telerik:GridViewDataColumn IsReadOnly="True" Header="Price" DataMemberBinding="{Binding Path=Price,StringFormat='{}{0:C}'}" />
            <telerik:GridViewDataColumn IsReadOnly="True" Header="Exposure" DataMemberBinding="{Binding Path=Exposure,StringFormat='{}{0:C}'}" />
            <telerik:GridViewDataColumn IsReadOnly="True" Header="Gain/Loss" DataMemberBinding="{Binding Path=GainLoss,StringFormat='{}{0:C}'}" />
            <telerik:GridViewDataColumn IsReadOnly="True" Header="Return" DataMemberBinding="{Binding Path=Return,StringFormat='{}{0:P}'}" />
            <telerik:GridViewDataColumn IsReadOnly="True" Header="Days Held" DataMemberBinding="{Binding Path=DaysHeld}" />
            <telerik:GridViewDataColumn IsReadOnly="True" Header="Comment" DataMemberBinding="{Binding Path=Comment}" />
        </telerik:RadGridView.Columns>
      </telerik:RadGridView>

      <telerik:RadGridView  Grid.Row="2" Grid.Column="2" Name="SummaryGrid" CanUserSelect="False" ItemContainerStyle="{StaticResource TradeItemStyle}" AlternationCount="2" AlternateRowBackground="Bisque" ShowGroupFooters="False" ShowColumnFooters="False" ItemsSource="{Binding Path=TradeResultsSummary, ValidatesOnDataErrors=True}" AutoGenerateColumns="False" AreRowDetailsFrozen="False">
          <telerik:RadGridView.Columns>
            <telerik:GridViewDataColumn IsReadOnly="True" Header="Portfolio Value" DataMemberBinding="{Binding Path=PortfolioValue,StringFormat='{}{0:C}'}" />
            <telerik:GridViewDataColumn IsReadOnly="True" Header="Portfolio Return" DataMemberBinding="{Binding Path=PortfolioReturn,StringFormat='{}{0:P}'}" />
            <telerik:GridViewDataColumn IsReadOnly="True" Header="Average Gain/Loss" DataMemberBinding="{Binding Path=AverageGainLoss,StringFormat='{}{0:C}'}" />
            <telerik:GridViewDataColumn IsReadOnly="True" Header="Average Holding Days" DataMemberBinding="{Binding Path=AverageHoldingDays}" />
            <telerik:GridViewDataColumn IsReadOnly="True" Header="Minimum Holdings Days" DataMemberBinding="{Binding Path=MinimumHoldingDays}" />
            <telerik:GridViewDataColumn IsReadOnly="True" Header="Maximum Holding Days" DataMemberBinding="{Binding Path=MaximumHoldingDays}" />
        </telerik:RadGridView.Columns>
      </telerik:RadGridView>
      </Grid>


    </DockPanel>
  </Grid>
</wpfx:BusyIndicator>
</UserControl>
