<Page
    x:Class="FinancialChartExplorer.Markers"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:FinancialChartExplorer"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:Finance="using:C1.Xaml.Chart.Finance"
    xmlns:Chart="using:C1.Xaml.Chart"
    xmlns:Interaction="using:C1.Xaml.Chart.Interaction"
    DataContext="{Binding RelativeSource={RelativeSource Mode=Self}}"
    mc:Ignorable="d">

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Finance:C1FinancialChart x:Name="financialChart"
                                  ItemsSource="{Binding Data}"
                                  BindingX="Date"
                                  ChartType="Candlestick"
                                  ToolTip="{x:Null}"
                                  Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
            <Finance:FinancialSeries SeriesName="BOX" ChartType="Line" Binding="High,Low,Open,Close"/>
            <Finance:C1FinancialChart.AxisX>
                <Chart:Axis LabelAngle="45"/>
            </Finance:C1FinancialChart.AxisX>
            <Finance:C1FinancialChart.Layers>
                <Interaction:C1LineMarker x:Name="marker" Lines="Both" Interaction="Move" Alignment="Auto" DragLines="True" PositionChanged="positionChanged"/>
            </Finance:C1FinancialChart.Layers>
        </Finance:C1FinancialChart>
        <StackPanel Orientation="Vertical" Grid.Row="1">
            <StackPanel.Resources>
                <local:EnumConverter x:Key="EnumConverter"/>
                <local:ReversedConverter x:Key="ReversedConverter"/>
                <DataTemplate x:Key="AlignmentTemplate">
                    <TextBlock>
                        <TextBlock.Inlines>
                            <Run Text="{Binding Source={StaticResource FinancialChartExplorerLocalization}, Path=AlignmentCaption}"/>
                            <Run Text="{Binding}"/>
                        </TextBlock.Inlines>
                    </TextBlock>
                </DataTemplate>
                <DataTemplate x:Key="InteractionTemplate">
                    <TextBlock>
                        <TextBlock.Inlines>
                            <Run Text="{Binding Source={StaticResource FinancialChartExplorerLocalization}, Path=InteractionCaption}"/>
                            <Run Text="{Binding}"/>
                        </TextBlock.Inlines>
                    </TextBlock>
                </DataTemplate>
                <DataTemplate x:Key="MarkerLinesTemplate">
                    <TextBlock>
                        <TextBlock.Inlines>
                            <Run Text="{Binding Source={StaticResource FinancialChartExplorerLocalization}, Path=MarkerLinesCaption}"/>
                            <Run Text="{Binding}"/>
                        </TextBlock.Inlines>
                    </TextBlock>
                </DataTemplate>
                <Style TargetType="ComboBox">
                    <Setter Property="Margin" Value="20 5"/>
                    <Setter Property="Width" Value="250"/>
                </Style>
            </StackPanel.Resources>
            <StackPanel Orientation="Horizontal">
                <ComboBox x:Name="cbAlignment"
                          ItemsSource="{Binding Alignments}"
                          ItemTemplate="{StaticResource AlignmentTemplate}"
                          SelectedValue="{Binding ElementName=marker, Path=Alignment, Mode=TwoWay, Converter={StaticResource EnumConverter}}"
                          IsEnabled="{Binding ElementName=cbSnpping, Path=IsChecked, Converter={StaticResource ReversedConverter}}"/>
                <ComboBox x:Name="cbInteraction" 
                          ItemsSource="{Binding Interactions}"
                          ItemTemplate="{StaticResource InteractionTemplate}"
                          SelectedValue="{Binding ElementName=marker, Path=Interaction, Mode=TwoWay, Converter={StaticResource EnumConverter}}"
                          IsEnabled="{Binding ElementName=cbSnpping, Path=IsChecked, Converter={StaticResource ReversedConverter}}"/>
            </StackPanel>
            <StackPanel Orientation="Horizontal">
                <ComboBox x:Name="cbMarkerLine"
                          ItemsSource="{Binding MarkerLines}"
                          ItemTemplate="{StaticResource MarkerLinesTemplate}"
                          SelectedValue="{Binding ElementName=marker, Path=Lines, Mode=TwoWay, Converter={StaticResource EnumConverter}}"
                          IsEnabled="{Binding ElementName=cbSnpping, Path=IsChecked, Converter={StaticResource ReversedConverter}}"/>
                <CheckBox x:Name="cbSnpping" Content="{Binding Source={StaticResource FinancialChartExplorerLocalization}, Path=SnappingCaptioin}" VerticalAlignment="Center" Margin="20 0" Checked="cbSnpping_Checked"  Unchecked="cbSnpping_Unchecked"/>
            </StackPanel>
        </StackPanel>
    </Grid>
</Page>
