<Page x:Class="FinancialChartExplorer.TrendLines"
      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:Chart="using:C1.Xaml.Chart.Finance"
      xmlns:c1="using:C1.Xaml"
      xmlns:FlexChart="using:C1.Xaml.Chart"
      mc:Ignorable="d" DataContext="{Binding RelativeSource={RelativeSource Mode=Self}}"
      d:DesignHeight="300" d:DesignWidth="300" >
    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Grid.Resources>
            <local:EnumConverter x:Key="EmConverter"/>
            <Style TargetType="TextBlock">
                <Setter Property="VerticalAlignment" Value="Center" />
            </Style>
        </Grid.Resources>
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Chart:C1FinancialChart x:Name="financialChart" ToolTipContent="{}{seriesName}&#x000A;{y:0.00}" BindingX="Date" Binding="Close" ChartType="Line" ItemsSource="{Binding Data}">
            <Chart:FinancialSeries SeriesName="Box" />
            <FlexChart:TrendLine x:Name="trendLine" SeriesName="Trend line" />
        </Chart:C1FinancialChart>
        <StackPanel x:Name="optionsPanel" Orientation="Horizontal" Margin="10" Grid.Row="1">
            <StackPanel Orientation="Horizontal">
                <TextBlock x:Name="tbFitType" Text="{Binding Path=FitTypeCaption, Source={StaticResource FinancialChartExplorerLocalization}}" Margin="10 0"/>
                <ComboBox x:Name="cbFitType" ItemsSource="{Binding FitType}" SelectedValue="{Binding ElementName=trendLine, Path=FitType, Converter={StaticResource EmConverter}, Mode=TwoWay}" Width="130" />
            </StackPanel>
            <StackPanel x:Name="spOrder" Orientation="Horizontal">
                <TextBlock x:Name="tbOrder" Text="{Binding Path=OrderCaption, Source={StaticResource FinancialChartExplorerLocalization}}" Margin="30 0 10 0"/>
                <c1:C1NumericBox x:Name="cbOrder" Value="{Binding ElementName=trendLine, Path=Order, Mode=TwoWay}" Minimum="2" Maximum="10" Width="200"/>
            </StackPanel>
            <StackPanel x:Name="spForecast" Orientation="Horizontal">
                <CheckBox x:Name="chkForecast" Margin="30 0 10 0" Content="Forecast"
                Checked="chkForecast_CheckedChanged" Unchecked="chkForecast_CheckedChanged"
                />
                <TextBlock Text="Forward" Margin="30 0 10 0"/>
                <c1:C1NumericBox Value="{Binding Forward, Mode=TwoWay}" Minimum="0" Maximum="100" />
                <TextBlock Text="Backward" Margin="30 0 10 0"/>
                <c1:C1NumericBox Value="{Binding Backward, Mode=TwoWay}" Minimum="0" Maximum="100" />
            </StackPanel>
        </StackPanel>
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup>
                <VisualState x:Name="NarrowLayout">
                    <VisualState.StateTriggers>
                        <AdaptiveTrigger MinWindowWidth="0"/>
                    </VisualState.StateTriggers>
                    <VisualState.Setters>
                        <Setter Target="financialChart.FontSize" Value="12"/>
                        <Setter Target="optionsPanel.Orientation" Value="Vertical" />
                        <Setter Target="tbFitType.FontSize" Value="12" />
                        <Setter Target="cbFitType.FontSize" Value="12" />
                        <Setter Target="tbOrder.Margin" Value="10 0" />
                        <Setter Target="tbOrder.FontSize" Value="12" />
                        <Setter Target="cbOrder.FontSize" Value="12" />
                        <Setter Target="cbFitType.Width" Value="160" />
                        <Setter Target="cbOrder.Width" Value="160" />
                        <Setter Target="spOrder.Margin" Value="10 0 0 0" />
                    </VisualState.Setters>
                </VisualState>
                <VisualState x:Name="WideLayout">
                    <VisualState.StateTriggers>
                        <AdaptiveTrigger MinWindowWidth="420" />
                    </VisualState.StateTriggers>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</Page>
