<Page x:Class="FinancialChartExplorer.Markers"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
      xmlns:local="using:FinancialChartExplorer"
      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" 
      d:DesignHeight="300" d:DesignWidth="300">
    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <StackPanel Orientation="Horizontal" Margin="20 0">
            <Button Content="&#xE700;" Background="{x:Null}" BorderThickness="0" FontSize="25" FontFamily="{ThemeResource SymbolThemeFontFamily}" Click="OnSplitterButtonClick"/>
            <TextBlock Text="{Binding Source={StaticResource FinancialChartExplorerLocalization}, Path=MarkersSettings}" VerticalAlignment="Center" />
        </StackPanel>
        <SplitView x:Name="splitter" DisplayMode="Overlay" Grid.Row="1">
            <SplitView.Pane>
                <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>
                    <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}}"/>
                    <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>
            </SplitView.Pane>
            <SplitView.Content>
                <Finance:C1FinancialChart x:Name="financialChart"
                                          ItemsSource="{Binding Data}"
                                          BindingX="Date"
                                          ChartType="Candlestick"
                                          ToolTip="{x:Null}"
                                          FontSize="10"
                                          LegendPosition="Bottom"
                                          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>
            </SplitView.Content>
        </SplitView>
    </Grid>
</Page>
