<Page
    x:Class="FinancialChartExplorer.FibonacciTool"
    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"
    xmlns:Xaml="using:C1.Xaml"
    DataContext="{Binding RelativeSource={RelativeSource Mode=Self}}"
    mc:Ignorable="d">

    <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=FibonacciSettings}" VerticalAlignment="Center" />
        </StackPanel>
        <SplitView x:Name="splitter" DisplayMode="Overlay" Grid.Row="1">
            <SplitView.Pane>
                <StackPanel Orientation="Vertical">
                    <StackPanel.Resources>
                        <Style TargetType="ComboBox">
                            <Setter Property="Width" Value="180"/>
                            <Setter Property="HorizontalAlignment" Value="Left"/>
                            <Setter Property="Margin" Value="20 0 0 10"/>
                        </Style>
                        <Style TargetType="Xaml:C1NumericBox">
                            <Setter Property="Width" Value="200"/>
                            <Setter Property="Margin" Value="10 0 0 10"/>
                            <Setter Property="Format" Value="g"/>
                        </Style>
                        <Style TargetType="TextBlock">
                            <Setter Property="VerticalAlignment" Value="Center"/>
                            <Setter Property="Margin" Value="20 0 0 0"/>
                        </Style>
                        <DataTemplate x:Key="cbFibonacciTypesTemplate">
                            <TextBlock>
                                <TextBlock.Inlines>
                                    <Run Text="{Binding Source={StaticResource FinancialChartExplorerLocalization}, Path=FibonacciTypeCaption}"/>
                                    <Run Text="{Binding}"/>
                                </TextBlock.Inlines>
                            </TextBlock>
                        </DataTemplate>
                        <DataTemplate x:Key="cbPositionsTemplate">
                            <TextBlock>
                                <TextBlock.Inlines>
                                    <Run Text="{Binding Source={StaticResource FinancialChartExplorerLocalization}, Path=PositionCaption}"/>
                                    <Run Text="{Binding}"/>
                                </TextBlock.Inlines>
                            </TextBlock>
                        </DataTemplate>
                        <DataTemplate x:Key="cbUptrendsTemplate">
                            <TextBlock>
                                <TextBlock.Inlines>
                                    <Run Text="{Binding Source={StaticResource FinancialChartExplorerLocalization}, Path=UptrendCaption}"/>
                                    <Run Text="{Binding}"/>
                                </TextBlock.Inlines>
                            </TextBlock>
                        </DataTemplate>
                        <local:EnumConverter x:Key="EmConverter"/>
                        <local:IntToVisibilityConverter x:Key="IntToVisibilityConverter"/>
                    </StackPanel.Resources>
                    <ComboBox x:Name="cbFibonacciTypes"
                      ItemsSource="{Binding FibonacciTypes}"
                      ItemTemplate="{StaticResource cbFibonacciTypesTemplate}"
                      SelectionChanged="cbFibonacciTypes_SelectionChanged"/>
                    <StackPanel Orientation="Vertical" Visibility="{Binding ElementName=cbFibonacciTypes, Path=SelectedIndex, Converter={StaticResource IntToVisibilityConverter}, ConverterParameter=0}">
                        <ComboBox SelectedValue="{Binding ElementName=financialChart, Path=Series[2].LabelPosition, Converter={StaticResource EmConverter}, Mode=TwoWay}"
                          ItemsSource="{Binding VerticalPositions}"
                          ItemTemplate="{StaticResource cbPositionsTemplate}"/>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="{Binding Source={StaticResource FinancialChartExplorerLocalization}, Path=StartXCaption}"/>
                            <Xaml:C1NumericBox Value="{Binding ElementName=financialChart, Path=Series[2].StartX, Mode=TwoWay}"/>
                        </StackPanel>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="{Binding Source={StaticResource FinancialChartExplorerLocalization}, Path=StartYCaption}"/>
                            <Xaml:C1NumericBox Value="{Binding ElementName=financialChart, Path=Series[2].StartY,Mode=TwoWay}"/>
                        </StackPanel>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="{Binding Source={StaticResource FinancialChartExplorerLocalization}, Path=EndXCaption}" Margin="25 0 0 10"/>
                            <Xaml:C1NumericBox Value="{Binding ElementName=financialChart, Path=Series[2].EndX, Mode=TwoWay}"/>
                        </StackPanel>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="{Binding Source={StaticResource FinancialChartExplorerLocalization}, Path=EndYCaption}" Margin="25 0 0 10"/>
                            <Xaml:C1NumericBox Value="{Binding ElementName=financialChart, Path=Series[2].EndY, Mode=TwoWay}" Format="f2" />
                        </StackPanel>
                    </StackPanel>
                    <StackPanel Orientation="Vertical" Visibility="{Binding ElementName=cbFibonacciTypes, Path=SelectedIndex, Converter={StaticResource IntToVisibilityConverter}, ConverterParameter=1}">
                        <ComboBox SelectedValue="{Binding ElementName=financialChart, Path=Series[3].LabelPosition, Converter={StaticResource EmConverter}, Mode=TwoWay}"
                          ItemsSource="{Binding VerticalPositions}"
                          ItemTemplate="{StaticResource cbPositionsTemplate}"/>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="{Binding Source={StaticResource FinancialChartExplorerLocalization}, Path=StartXCaption}"/>
                            <Xaml:C1NumericBox Value="{Binding ElementName=financialChart, Path=Series[3].StartX, Mode=TwoWay}"/>
                        </StackPanel>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="{Binding Source={StaticResource FinancialChartExplorerLocalization}, Path=StartYCaption}"/>
                            <Xaml:C1NumericBox Value="{Binding ElementName=financialChart, Path=Series[3].StartY, Mode=TwoWay}"/>
                        </StackPanel>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="{Binding Source={StaticResource FinancialChartExplorerLocalization}, Path=EndXCaption}" Margin="25 0 0 10"/>
                            <Xaml:C1NumericBox Value="{Binding ElementName=financialChart, Path=Series[3].EndX, Mode=TwoWay}"/>
                        </StackPanel>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="{Binding Source={StaticResource FinancialChartExplorerLocalization}, Path=EndYCaption}" Margin="25 0 0 10"/>
                            <Xaml:C1NumericBox Value="{Binding ElementName=financialChart, Path=Series[3].EndY, Mode=TwoWay}"/>
                        </StackPanel>
                    </StackPanel>
                    <StackPanel Orientation="Vertical" Visibility="{Binding ElementName=cbFibonacciTypes, Path=SelectedIndex, Converter={StaticResource IntToVisibilityConverter}, ConverterParameter=2}">
                        <ComboBox x:Name="cbUptrends"
                          SelectedValue="{Binding ElementName=financialChart, Path=Series[1].Uptrend, Converter={StaticResource EmConverter}, Mode=TwoWay}"
                          ItemsSource="{Binding Uptrends}"
                          ItemTemplate="{StaticResource cbUptrendsTemplate}"/>
                        <ComboBox x:Name="cbPositions"
                          SelectedValue="{Binding ElementName=financialChart, Path=Series[1].LabelPosition, Converter={StaticResource EmConverter}, Mode=TwoWay}"
                          ItemsSource="{Binding Positions}"
                          ItemTemplate="{StaticResource cbPositionsTemplate}"/>
                        <CheckBox x:Name="cbRangeSelector" Margin="20 0" Content="{Binding Source={StaticResource FinancialChartExplorerLocalization}, Path=RangeSelectorCaption}" Checked="cbRangeSelector_Checked" Unchecked="cbRangeSelector_Unchecked"/>
                    </StackPanel>
                    <StackPanel Orientation="Vertical" Visibility="{Binding ElementName=cbFibonacciTypes, Path=SelectedIndex, Converter={StaticResource IntToVisibilityConverter}, ConverterParameter=3}">
                        <ComboBox SelectedValue="{Binding ElementName=financialChart, Path=Series[4].LabelPosition, Converter={StaticResource EmConverter}, Mode=TwoWay}"
                          ItemsSource="{Binding TimeZonesPositions}"
                          ItemTemplate="{StaticResource cbPositionsTemplate}"/>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="{Binding Source={StaticResource FinancialChartExplorerLocalization}, Path=StartXCaption}"/>
                            <Xaml:C1NumericBox Value="{Binding ElementName=financialChart, Path=Series[4].StartX, Mode=TwoWay}"/>
                        </StackPanel>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="{Binding Source={StaticResource FinancialChartExplorerLocalization}, Path=StartYCaption}"/>
                            <Xaml:C1NumericBox Value="{Binding ElementName=financialChart, Path=Series[4].EndX, Mode=TwoWay}"/>
                        </StackPanel>
                    </StackPanel>
                </StackPanel>
            </SplitView.Pane>
            <SplitView.Content>
                <Finance:C1FinancialChart x:Name="financialChart" FontSize="12" LegendPosition="Bottom" ItemsSource="{Binding Data}" BindingX="Date" ChartType="Candlestick" ToolTipContent="{}{seriesName}&#x000A;{Date} {y}">
                    <Finance:FinancialSeries x:Name="fs" Binding="High,Low,Open,Close" ChartType="Line" SymbolSize="5" SeriesName="BOX"/>
                    <Finance:Fibonacci x:Name="fibonacci" Binding="Close">
                        <Finance:Fibonacci.Style>
                            <Chart:ChartStyle Fill="Red" Stroke="Red" StrokeThickness="0.5" FontSize="10"/>
                        </Finance:Fibonacci.Style>
                    </Finance:Fibonacci>
                    <Finance:FibonacciArcs x:Name="arc" Binding="Close" StartX="46" StartY="19.75" EndX="54" EndY="17.1" />
                    <Finance:FibonacciFans x:Name="fans" Binding="Close" StartX="10" StartY="18.12" EndX="32" EndY="20.53" />
                    <Finance:FibonacciTimeZones x:Name="timeZones" Binding="Close" StartX="0" EndX="3" />
                    <Finance:C1FinancialChart.AxisX>
                        <Chart:Axis LabelAngle="45" MajorUnit="3" />
                    </Finance:C1FinancialChart.AxisX>
                    <Finance:C1FinancialChart.Layers>
                        <Interaction:C1RangeSelector x:Name="rangeSelector" ValueChanged="C1RangeSelector_ValueChanged"/>
                    </Finance:C1FinancialChart.Layers>
                </Finance:C1FinancialChart>
            </SplitView.Content>
        </SplitView>
    </Grid>
</Page>
