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

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Grid.Resources>
            <local:VisibilityConverter x:Key="visibilityConverter" />
        </Grid.Resources>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition />
        </Grid.RowDefinitions>
        <StackPanel Orientation="Horizontal">
            <CheckBox Content="{Binding CbMarch, Source={StaticResource FlexChart101Localization}}" 
                      IsChecked="{Binding ElementName=marchSeries, Path=Visibility, Mode=TwoWay, Converter={StaticResource visibilityConverter}}" />
            <CheckBox x:Name="cbApril" Content="{Binding CbApril, Source={StaticResource FlexChart101Localization}}" Margin="20 0"
                      IsChecked="{Binding ElementName=aprilSeries, Path=Visibility, Mode=TwoWay, Converter={StaticResource visibilityConverter}}" />
            <CheckBox Content="{Binding CbMay, Source={StaticResource FlexChart101Localization}}" 
                      IsChecked="{Binding ElementName=maySeries, Path=Visibility, Mode=TwoWay, Converter={StaticResource visibilityConverter}}" />
        </StackPanel>
        <Chart:C1FlexChart x:Name="flexChart" ItemsSource="{Binding DataContext.Data}" BindingX="Fruit" LegendToggle="True" Grid.Row="1">
            <Chart:C1FlexChart.Series>
                <Chart:Series SeriesName="March" x:Name="marchSeries" Binding="March"/>
                <Chart:Series SeriesName="April" x:Name="aprilSeries" Binding="April"/>
                <Chart:Series SeriesName="May" x:Name="maySeries" Binding="May"/>
            </Chart:C1FlexChart.Series>
        </Chart:C1FlexChart>
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup>
                <VisualState x:Name="WideLayout">
                    <VisualState.StateTriggers>
                        <AdaptiveTrigger MinWindowWidth="540" />
                    </VisualState.StateTriggers>
                </VisualState>
                <VisualState x:Name="NarrowLayout">
                    <VisualState.StateTriggers>
                        <AdaptiveTrigger MinWindowWidth="0" />
                    </VisualState.StateTriggers>
                    <VisualState.Setters>
                        <Setter Target="flexChart.LegendPosition" Value="Bottom" />
                        <Setter Target="cbApril.Margin" Value="0" />
                    </VisualState.Setters>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</Page>
