<UserControl x:Class="FinancialChartExplorer.Indicators"
             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="clr-namespace:FinancialChartExplorer"
             xmlns:c1="http://schemas.componentone.com/winfx/2006/xaml"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300" DataContext="{Binding RelativeSource={RelativeSource Mode=Self}}">
    <Grid Margin="10 0 0 0">
        <Grid.Resources>
            <local:IntToSeriesVisibilityConverter x:Key="ITSVConverter"/>
            <local:IntToVisibilityConverter x:Key="ITVConverter"/>
        </Grid.Resources>
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition Height="200"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <c1:C1FinancialChart x:Name="financialChart"
                             BindingX="Date"
                             Binding="Close" 
                             ChartType="Line" 
                             ItemsSource="{Binding Data}"
                             LegendPosition="Top"
                             ToolTipContent="{}{seriesName}&#x000A;Date: {Date}&#x000A;Y: {y:n2}&#x000A;Volume: {Volume:n0}"
                             Rendered="OnFinancialChartRendered">
            <c1:FinancialSeries SeriesName="BOX" />
            <c1:C1FinancialChart.AxisX>
                <c1:Axis LabelAngle="45" MajorUnit="3"/>
            </c1:C1FinancialChart.AxisX>
        </c1:C1FinancialChart>
        <c1:C1FinancialChart x:Name="indicatorChart"
                             BindingX="Date"
                             Binding="High,Low,Close"
                             LegendPosition="Bottom"
                             ItemsSource="{Binding Data}"
                             MouseMove="indicatorChart_MouseMove"
                             Background="White"
                             ToolTipContent="{}{seriesName}&#x000A;Date: {Date}&#x000A;Y: {y:n2}&#x000A;Volume: {Volume:n0}"
                             Grid.Row="1">
            <c1:ATR x:Name="atr" SeriesName="ATR" Visibility="{Binding Source={x:Reference Name=cbIndicatorType}, Path=SelectedIndex, Converter={StaticResource ITSVConverter}, ConverterParameter=0}"/>
            <c1:RSI x:Name="rsi" SeriesName="RSI" Visibility="{Binding Source={x:Reference Name=cbIndicatorType}, Path=SelectedIndex, Converter={StaticResource ITSVConverter}, ConverterParameter=1}"/>
            <c1:CCI x:Name="cci" SeriesName="CCI" Visibility="{Binding Source={x:Reference Name=cbIndicatorType}, Path=SelectedIndex, Converter={StaticResource ITSVConverter}, ConverterParameter=2}"/>
            <c1:WilliamsR x:Name="wi" SeriesName="Williams %R" Visibility="{Binding Source={x:Reference Name=cbIndicatorType}, Path=SelectedIndex, Converter={StaticResource ITSVConverter}, ConverterParameter=3}"/>
            <c1:Macd x:Name="macd" SeriesName="MACD, Signal" Visibility="{Binding Source={x:Reference Name=cbIndicatorType}, Path=SelectedIndex, Converter={StaticResource ITSVConverter}, ConverterParameter=4}">
                <c1:Macd.MacdLineStyle>
                    <c1:ChartStyle Stroke="#bfa554" />
                </c1:Macd.MacdLineStyle>
                <c1:Macd.SignalLineStyle>
                    <c1:ChartStyle Stroke="#bf8c54" />
                </c1:Macd.SignalLineStyle>
            </c1:Macd>
            <c1:MacdHistogram x:Name="histogram" SeriesName="MACD Histogram" Visibility="{Binding Source={x:Reference Name=cbIndicatorType}, Path=SelectedIndex, Converter={StaticResource ITSVConverter}, ConverterParameter=4}"/>
            <c1:Stochastic x:Name="stochastic" SeriesName="%K,%D" Visibility="{Binding Source={x:Reference Name=cbIndicatorType}, Path=SelectedIndex, Converter={StaticResource ITSVConverter}, ConverterParameter=5}"/>
            <c1:C1FinancialChart.AxisX>
                <c1:Axis LabelAngle="45" MajorUnit="3"/>
            </c1:C1FinancialChart.AxisX>
        </c1:C1FinancialChart>
        <StackPanel Orientation="Vertical" Margin="10" Grid.Row="2">
            <StackPanel.Resources>
                <Style TargetType="c1:C1NumericBox">
                    <Setter Property="Width" Value="80"/>
                    <Setter Property="Minimum" Value="2"/>
                    <Setter Property="Maximum" Value="86"/>
                </Style>
                <Style TargetType="TextBlock">
                    <Setter Property="Margin" Value="10 0"/>
                </Style>
            </StackPanel.Resources>
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="Indicator Type" Margin="10 0"/>
                <ComboBox x:Name="cbIndicatorType" ItemsSource="{Binding IndicatorType}" SelectedIndex="0" Width="180"/>
            </StackPanel>
            <StackPanel Orientation="Horizontal" x:Name="spNormalOptions" Margin="0 5"
                        Visibility="{Binding ElementName=cbIndicatorType, Path=SelectedIndex, Converter={StaticResource ITVConverter}, ConverterParameter='0 1 2 3'}">
                <TextBlock Text="Period" Margin="50 0 10 0"/>
                <c1:C1NumericBox x:Name="cbPeriod" Value="14" ValueChanged="OnPeriodValueChanged"/>
            </StackPanel>
            <StackPanel Orientation="Horizontal" x:Name="spMacdOptions" Margin="0 5"
                        Visibility="{Binding ElementName=cbIndicatorType, Path=SelectedIndex, Converter={StaticResource ITVConverter}, ConverterParameter=4}">
                <TextBlock Text="Fast Period" Margin="28 0 10 0"/>
                <c1:C1NumericBox x:Name="cbFastPeriod" Value="12" ValueChanged="OnFastPeriodValueChanged"/>
                <TextBlock Text="Slow Period"/>
                <c1:C1NumericBox x:Name="cbSlowPeriod" Value="26" ValueChanged="OnSlowPeriodValueChanged" />
                <TextBlock Text="Signal Smoothing Period"/>
                <c1:C1NumericBox x:Name="cbSmoothingPeriod" Value="9" ValueChanged="OnSmoothingPeriodValueChanged"/>
            </StackPanel>
            <StackPanel Orientation="Horizontal" x:Name="spStochasticOptions" Margin="0 5" 
                        Visibility="{Binding ElementName=cbIndicatorType, Path=SelectedIndex, Converter={StaticResource ITVConverter}, ConverterParameter=5}">
                <TextBlock Text="K Period" Margin="40 0 10 0"/>
                <c1:C1NumericBox x:Name="cbKPeriod" Value="14" ValueChanged="OnKPeriodValueChanged"/>
                <TextBlock Text="D Period"/>
                <c1:C1NumericBox x:Name="cbDPeriod" Value="3" ValueChanged="OnDPeriodValueChanged" />
                <TextBlock Text="Signal Smoothing Period"/>
                <c1:C1NumericBox x:Name="cbStochasticSmoothingPeriod" Minimum="1" Value="1" ValueChanged="OnStochasticSmoothingPeriodValueChanged"/>
            </StackPanel>
        </StackPanel>
    </Grid>
</UserControl>
