<UserControl 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:c1="http://schemas.componentone.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:FinancialChartExplorer"
             DataContext="{Binding RelativeSource={RelativeSource Mode=Self}}"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <c1:C1FinancialChart x:Name="financialChart"
                             ItemsSource="{Binding Data}"
                             BindingX="Date"
                             ChartType="Candlestick"
                             ToolTip="{x:Null}"
                             Background="White">
            <c1:FinancialSeries SeriesName="BOX" ChartType="Line" Binding="High,Low,Open,Close"/>
            <c1:C1FinancialChart.AxisX>
                <c1:Axis LabelAngle="45"/>
            </c1:C1FinancialChart.AxisX>
            <c1:C1FinancialChart.Layers>
                <c1:C1LineMarker x:Name="marker" Lines="Both" Interaction="Move" Alignment="Auto" DragLines="True" PositionChanged="positionChanged"/>
            </c1:C1FinancialChart.Layers>
        </c1: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="Content Alignment: "/>
                            <Run Text="{Binding Path=.}"/>
                        </TextBlock.Inlines>
                    </TextBlock>
                </DataTemplate>
                <DataTemplate x:Key="InteractionTemplate">
                    <TextBlock>
                        <TextBlock.Inlines>
                            <Run Text="Interaction: "/>
                            <Run Text="{Binding Path=.}"/>
                        </TextBlock.Inlines>
                    </TextBlock>
                </DataTemplate>
                <DataTemplate x:Key="MarkerLinesTemplate">
                    <TextBlock>
                        <TextBlock.Inlines>
                            <Run Text="Marker Lines: "/>
                            <Run Text="{Binding Path=.}"/>
                        </TextBlock.Inlines>
                    </TextBlock>
                </DataTemplate>
                <Style TargetType="ComboBox">
                    <Setter Property="Margin" Value="20 5"/>
                    <Setter Property="Width" Value="180"/>
                </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="Snapping" VerticalAlignment="Center" Margin="20 0" Checked="cbSnpping_Checked"  Unchecked="cbSnpping_Unchecked"/>
            </StackPanel>
        </StackPanel>
    </Grid>
</UserControl>
