<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">
    <Page.Resources>
        <local:OrderVisibilityConverter x:Key="orderVisibilityConverter"/>
        <local:EnumConverter x:Key="enumConverter" />
        <local:BoolToVisibilityConverter x:Key="BTVConverter"/>
    </Page.Resources>
    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <RichTextBox:C1RichTextBox x:Name="rich" IsReadOnly="True" BorderThickness="0" Margin="20" 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}" LegendPosition="Bottom" Grid.Row="1" Rendered="HandleRendered" PointerPressed="HandlePointerPressed">
            <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.BottomAppBar>
        <CommandBar>
            <AppBarButton Icon="Setting" Label="{Binding SettingsCaption, Source={StaticResource FlexChartExplorerLocalization}}">
                <AppBarButton.Flyout>
                    <Flyout>
                        <StackPanel>
                            <StackPanel>
                                <CheckBox Content="{Binding ShowCaption, Source={StaticResource FlexChartExplorerLocalization}}" x:Name="cbShow" VerticalAlignment="Center" MinWidth="0"/>
                                <ComboBox ItemsSource="{Binding FitTypes}" SelectedValue="{Binding Path=TrendLineSeries.FitType, Mode=TwoWay, Converter={StaticResource enumConverter}, ConverterParameter=FitType}" Margin="0 10" Width="200">
                                    <ComboBox.ItemTemplate>
                                        <DataTemplate>
                                            <TextBlock>
                                                <TextBlock.Inlines>
                                                    <Run Text="{Binding FitTypeCaption, Source={StaticResource FlexChartExplorerLocalization}}"/>
                                                    <Run Text="{Binding}" />
                                                </TextBlock.Inlines>
                                            </TextBlock>
                                        </DataTemplate>
                                    </ComboBox.ItemTemplate>
                                </ComboBox>
                            </StackPanel>
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Text="{Binding OrderCaption, Source={StaticResource FlexChartExplorerLocalization}}" Margin="0 0 5 0" VerticalAlignment="Center" Visibility="{Binding Path=TrendLineSeries.FitType, Converter={StaticResource orderVisibilityConverter}}" />
                                <Xaml:C1NumericBox Value="{Binding Path=TrendLineSeries.Order, Mode=TwoWay}" Visibility="{Binding Path=TrendLineSeries.FitType, Converter={StaticResource orderVisibilityConverter}}" Minimum="1" Maximum="9" Width="160" />
                            </StackPanel>
                        </StackPanel>
                    </Flyout>
                </AppBarButton.Flyout>
            </AppBarButton>
        </CommandBar>
    </Page.BottomAppBar>
</Page>
