ChartTrader Template |
User can change the complete look and feel of the ChartTrader pane in the Chart View by building custom xaml template. The ChartTrader template is binded with the ChartViewModel object. Perticularly the OrderHelper object.
Any custom ChartTrader xaml template must have the suffix ChartTrader. For example if you name your custom ChartTrader template as MyCT, then the dataTemplate's key will be MyCTChartTrader.
<DataTemplate x:Key="MyCTChartTrader"> <!-- design your template here --> </DataTemplate>
xmlns:bControls="clr-namespace:SharpCharts.Base.Controls;assembly=SharpCharts.Base" xmlns:bCommon="clr-namespace:SharpCharts.Base.Common;assembly=SharpCharts.Base" xmlns:bOrder="clr-namespace:SharpCharts.Base.Order;assembly=SharpCharts.Base" xmlns:bData="clr-namespace:SharpCharts.Base.Data;assembly=SharpCharts.Base"
<Style TargetType="{x:Type Grid}" x:Key="overnightPositionStyleKey"> <Style.Triggers> <DataTrigger Binding="{Binding MarketPosition}" Value="Long"> <Setter Property="Background" Value="Green" /> </DataTrigger> <DataTrigger Binding="{Binding MarketPosition}" Value="Short"> <Setter Property="Background" Value="Red" /> </DataTrigger> </Style.Triggers> </Style> <Style TargetType="{x:Type Grid}" x:Key="marginPositionStyleKey"> <Style.Triggers> <DataTrigger Binding="{Binding MarketPosition}" Value="Long"> <Setter Property="Background" Value="LightGreen" /> </DataTrigger> <DataTrigger Binding="{Binding MarketPosition}" Value="Short"> <Setter Property="Background" Value="Pink" /> </DataTrigger> </Style.Triggers> </Style> <bCommon:ControlParentConverter x:Key="controlParentConverterKey" /> <DataTemplate x:Key="DefaultChartTrader"> <Grid DataContext="{Binding DataContext, RelativeSource={RelativeSource AncestorType={x:Type Window}}}"> <Grid.ColumnDefinitions> <ColumnDefinition Width="1*" /> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition /> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <bControls:DomUserControl OrderView="{Binding DomHelper.DomOrderView}" Instrument="{Binding Bars.Instrument,Mode=OneWay}" OrderHelper="{Binding OrderHelper, Mode=OneWay}" DomHelper="{Binding DomHelper, Mode=OneWay}" bCommon:SizeObserver.Observe="True" bCommon:SizeObserver.ObservedWidth="{Binding DomHelper.DomWidth, Mode=OneWayToSource}" > </bControls:DomUserControl> <Expander Grid.Row="1" Content="{Binding OrderHelper}" Header="{Binding OrderHelper.Position}" IsExpanded="{Binding IsExpanded, Mode=TwoWay}" MinWidth="150"> <Expander.HeaderTemplate> <DataTemplate> <Grid Grid.Row="1" HorizontalAlignment="{Binding HorizontalAlignment, Mode=OneWayToSource, RelativeSource={RelativeSource AncestorType={x:Type ContentPresenter}}}"> <Grid.Style> <Style TargetType="{x:Type Grid}"> <Style.Triggers> <DataTrigger Binding="{Binding MarketPosition}" Value="Long"> <Setter Property="Background" Value="Green" /> </DataTrigger> <DataTrigger Binding="{Binding MarketPosition}" Value="Short"> <Setter Property="Background" Value="Red" /> </DataTrigger> </Style.Triggers> </Style> </Grid.Style> <Grid.ColumnDefinitions> <ColumnDefinition Width="1*" /> <ColumnDefinition Width="1*" /> <ColumnDefinition Width="1*" /> </Grid.ColumnDefinitions> <TextBlock Text="{Binding MarketPosition}" Margin="5,0" FontWeight="SemiBold" TextAlignment="Center" HorizontalAlignment="Center"/> <TextBlock Grid.Column="1" Text="{Binding Quantity}" Margin="5,0" FontWeight="SemiBold" TextAlignment="Center" HorizontalAlignment="Center"/> <TextBlock Grid.Column="2" Text="{Binding UnrealizedPnL}" Margin="5,0" FontWeight="SemiBold" TextAlignment="Center" HorizontalAlignment="Center"/> </Grid> </DataTemplate> </Expander.HeaderTemplate> <Expander.ContentTemplate> <DataTemplate> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="1*" /> <ColumnDefinition Width="1*" /> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <Menu Margin="5" MaxHeight="23"> <MenuItem Header="{Loc LblClosePosition}" ItemsSource="{Binding ProductTypes}" Height="{Binding ActualHeight, RelativeSource={RelativeSource AncestorType=Menu}}" Width="{Binding ActualWidth, RelativeSource={RelativeSource AncestorType={x:Type Menu}}}"> <MenuItem.ItemContainerStyle> <Style TargetType="{x:Type MenuItem}" BasedOn="{StaticResource ResourceKey={x:Type MenuItem}}"> <Setter Property="Command" Value="{Binding DataContext.ClosePositionCommand, RelativeSource={RelativeSource AncestorType={x:Type Menu}}}" /> <Setter Property="CommandParameter" Value="{Binding Path=.}" /> </Style> </MenuItem.ItemContainerStyle> </MenuItem> </Menu> <Menu Margin="5" Grid.Column="1" MaxHeight="23"> <MenuItem Header="{Loc LblReverse}" ItemsSource="{Binding ProductTypes}" Height="{Binding ActualHeight, RelativeSource={RelativeSource AncestorType=Menu}}" Width="{Binding ActualWidth, RelativeSource={RelativeSource AncestorType={x:Type Menu}}}"> <MenuItem.ItemContainerStyle> <Style TargetType="{x:Type MenuItem}" BasedOn="{StaticResource ResourceKey={x:Type MenuItem}}"> <Setter Property="Command" Value="{Binding DataContext.ReversePositionCommand, RelativeSource={RelativeSource AncestorType={x:Type Menu}}}" /> <Setter Property="CommandParameter" Value="{Binding Path=.}" /> </Style> </MenuItem.ItemContainerStyle> </MenuItem> </Menu> <TextBlock Grid.Row="1" Grid.ColumnSpan="2" Text="{Loc LblQuantity}" FontSize="10" /> <bControls:IntegerUpDown Grid.Row="2" Grid.ColumnSpan="2" Margin="5,0,5,5" Value="{Binding Quantity}" Increment="{Binding Instrument.QuantitySize, Mode=OneWay}" Minimum="1" /> <TextBlock Grid.Row="3" Text="{Loc LblAccounts}" FontSize="10"/> <ComboBox x:Name="cmbAccount" Grid.Row="4" Margin="5,0,5,5" IsEnabled="{Binding HasItems, RelativeSource={RelativeSource Self}}" ItemsSource="{Binding AccountsView}" DisplayMemberPath="Description" SelectedValue="{Binding Account}" > </ComboBox> <TextBlock Grid.Row="3" Grid.Column="1" Text="{Loc LblTIF}" FontSize="10" /> <ComboBox Grid.Row="4" Grid.Column="1" Margin="5,0,5,5" ItemsSource="{Binding Account.TimeInForces}" SelectedItem="{Binding TimeInForce}" IsEnabled="{Binding ElementName=cmbAccount, Path=IsEnabled}"> <ComboBox.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding Path=., Converter={StaticResource ResourceKey={x:Static bCommon:ResourceKey.LocalizationConverterKey}}}" /> </DataTemplate> </ComboBox.ItemTemplate> </ComboBox> <TextBlock Grid.Row="5" Text="{Loc LblProduct}" FontSize="10" /> <ComboBox Grid.Row="6" ItemsSource="{Binding Account.SupportedProductTypes}" IsEnabled="{Binding HasItems, RelativeSource={RelativeSource Self}}" Margin="5,0,5,5" SelectedItem="{Binding ProductType}" > <ComboBox.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding Path=., Converter={StaticResource ResourceKey={x:Static bCommon:ResourceKey.LocalizationConverterKey}}}" /> </DataTemplate> </ComboBox.ItemTemplate> </ComboBox> <TextBlock Grid.Row="5" Grid.Column="1" Text="{Loc LblOrderTemplate}" FontSize="10" /> <bControls:OrderTemplateUserControl Grid.Row="6" Grid.Column="1" ItemsView="{Binding OrderTemplates}" SelectedItem="{Binding OrderTemplate}" Margin="5,0,5,5" /> </Grid> </DataTemplate> </Expander.ContentTemplate> </Expander> <Grid.ContextMenu> <ContextMenu> <MenuItem Header="{Loc LblRowCount, Converter={StaticResource locConverter}, ConverterParameter=LblRowCount}"> <MenuItem.ItemsSource> <x:Array Type="FrameworkElement"> <MenuItem> <MenuItem.Template> <ControlTemplate> <bControls:IntegerUpDown Value="{Binding DataContext.DomHelper.RowCount, RelativeSource={RelativeSource AncestorType={x:Type Window}}}" MinWidth="100" Minimum="1" Maximum="20" Increment="1" /> </ControlTemplate> </MenuItem.Template> </MenuItem> </x:Array> </MenuItem.ItemsSource> </MenuItem> <MenuItem Header="{Loc LblDomScripts, Converter={StaticResource locConverter}, ConverterParameter=LblDomScripts}" Command="{Binding DomHelper.SelectDomScriptCommand, Mode=OneWay}" CommandParameter="{Binding PlacementTarget, Converter={StaticResource controlParentConverterKey}, RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}}" /> <MenuItem Header="{Loc LblProperty, Converter={StaticResource locConverter}, ConverterParameter=LblProperty}" Command="bControls:DomUserControl.DomPropertiesCommand" CommandParameter="{Binding DomHelper.Properties}" /> </ContextMenu> </Grid.ContextMenu> </Grid> </DataTemplate>