<Page
    x:Class="FlexChartExplorer.TrendLine"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:FlexChartExplorer"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:Chart="using:C1.Xaml.Chart"
    xmlns:Xaml="using:C1.Xaml"
    xmlns:RichTextBox="using:C1.Xaml.RichTextBox"
    mc:Ignorable="d"
    DataContext="{Binding RelativeSource={RelativeSource Mode=Self}}"
    d:DesignHeight="300"
    d:DesignWidth="400">

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Grid.Resources>
            <local:EnumConverter x:Key="enumConverter" />
            <local:OrderVisibilityConverter x:Key="orderVisibilityConverter"/>
            <local:BoolToVisibilityConverter x:Key="BTVConverter"/>
            <Style TargetType="ComboBox">
                <Setter Property="ItemTemplate">
                    <Setter.Value>
                        <DataTemplate>
                            <TextBlock>
                                <TextBlock.Inlines>
                                    <Run Text="{Binding FitTypeCaption, Source={StaticResource FlexChartExplorerLocalization}}"/>
                                    <Run Text="{Binding}" />
                                </TextBlock.Inlines>
                            </TextBlock>
                        </DataTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </Grid.Resources>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition />
        </Grid.RowDefinitions>
        <StackPanel Orientation="Horizontal" Margin="10">
            <CheckBox Content="{Binding ShowCaption, Source={StaticResource FlexChartExplorerLocalization}}" x:Name="cbShow" VerticalAlignment="Center" Margin="10 0"/>
            <ComboBox ItemsSource="{Binding FitTypes}" SelectedValue="{Binding ElementName=trendLine, Path=FitType, Mode=TwoWay, Converter={StaticResource enumConverter}, ConverterParameter=FitType}" Width="200"/>
            <TextBlock Text="{Binding OrderCaption, Source={StaticResource FlexChartExplorerLocalization}}" Margin="20 0 10 0" VerticalAlignment="Center" Visibility="{Binding ElementName=trendLine, Path=FitType, Converter={StaticResource orderVisibilityConverter}}" />
            <Xaml:C1NumericBox Value="{Binding ElementName=trendLine, Path=Order, Mode=TwoWay}" Visibility="{Binding ElementName=trendLine, Path=FitType, Converter={StaticResource orderVisibilityConverter}}" Minimum="1" Maximum="9" Width="200" />
        </StackPanel>
        <RichTextBox:C1RichTextBox x:Name="rich" IsReadOnly="True" BorderThickness="0" Margin="20" Grid.Row="1" Canvas.ZIndex="1" 
                          VerticalAlignment="Top" HorizontalAlignment="Left" Background="{x:Null}"
                          HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden" IsHitTestVisible="False"
                          Visibility="{Binding ElementName=cbShow, Path=IsChecked, Converter={StaticResource BTVConverter}}" />
        <Chart:C1FlexChart x:Name="flexChart" RenderMode="Direct2D" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" ChartType="LineSymbols" ItemsSource="{Binding Data}" ToolTipContent="{}{y}" Grid.Row="1" Rendered="HandleRendered">
            <Chart:C1FlexChart.AxisY>
                <Chart:Axis Min="0" Max="100" AxisLine="False" MajorGrid="True" MajorTickMarks="None" />
            </Chart:C1FlexChart.AxisY>
            <Chart:Series SeriesName="Base Data" BindingX="X" Binding="Y"/>
            <Chart:TrendLine SeriesName="Trend Line" x:Name="trendLine" Binding="Y" BindingX="X" Order="4"/>
        </Chart:C1FlexChart>
    </Grid>
</Page>
