<Page x:Class="DrillDown.ColumnPie"
      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:DrillDown"
      xmlns:c1="http://schemas.componentone.com/winfx/2006/xaml"
      xmlns:Chart="using:C1.Xaml.Chart"
      mc:Ignorable="d" 
      d:DesignHeight="300" d:DesignWidth="300">

    <Grid Margin="10">
        <Grid.Resources>
            <local:IntToVisibilityConverter x:Key="ITVConverter"/>
            <local:ShowNavigateConverter x:Key="SNConverter"/>
            <local:SelectToVisibilityConverter x:Key="Select2VisibilityConverter"/>
            <Style TargetType="StackPanel">
                <Setter Property="Orientation" Value="Horizontal"/>
                <Setter Property="Margin" Value="0 5"/>
            </Style>
            <Style TargetType="ComboBox">
                <Setter Property="Margin" Value="10 0"/>
            </Style>
        </Grid.Resources>

        <Grid Margin="10">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition />
            </Grid.RowDefinitions>
            <StackPanel Orientation="Vertical">
                <StackPanel>
                    <TextBlock>
                        <TextBlock.Inlines>
                            <Run Text="Step 1)" FontWeight="Bold"/>
                            <Run Text="Select how would you like to group the data:"/>
                        </TextBlock.Inlines>
                    </TextBlock>
                    <ComboBox x:Name="cbGroupBy"
                                      SelectedValuePath="Value"
                                      DisplayMemberPath="Key"
                                      ItemsSource="{Binding Groups}"
                                      SelectedValue="{Binding GroupBy, Mode=TwoWay}"
                                      />
                </StackPanel>
                <StackPanel>
                    <TextBlock>
                        <TextBlock.Inlines>
                            <Run Text="Step 2)" FontWeight="Bold"/>
                            <Run Text="Select how would you like to aggregate the data:"/>
                        </TextBlock.Inlines>
                    </TextBlock>
                    <ComboBox x:Name="cbAggregate"
                                      DisplayMemberPath="Key"
                                      SelectedValuePath="Value"
                                      ItemsSource="{Binding Aggregates}"
                                      SelectedValue="{Binding DataLayer.AggregateType, Mode=TwoWay}"
                                      />
                </StackPanel>
                <StackPanel>
                    <TextBlock>
                        <TextBlock.Inlines>
                            <Run Text="Step 3)" FontWeight="Bold"/>
                            <Run Text="Select how would you like to show the data:" />
                        </TextBlock.Inlines>
                    </TextBlock>
                    <ComboBox x:Name="cbChartTypes" ItemsSource="{Binding ChartTypes}" SelectedValue="{Binding ChartType}" />
                </StackPanel>
                <TextBlock>
                    <TextBlock.Inlines>
                        <Run Text="Step 4)" FontWeight="Bold"/>
                        <Run Text="Click a column or selector to drill down into the details, or click on the header to return to a higher level."/>
                    </TextBlock.Inlines>
                </TextBlock>
                <StackPanel Visibility="{Binding ElementName=cbChartTypes, Path=SelectedIndex, Converter={StaticResource ITVConverter}, ConverterParameter='0 1'}">
                    <StackPanel.Resources>
                        <Style TargetType="TextBlock">
                            <Setter Property="VerticalAlignment" Value="Center"/>
                            <Setter Property="FontSize" Value="15"/>
                        </Style>
                    </StackPanel.Resources>
                    <StackPanel Visibility="{Binding DataLayer.Depth, Converter={StaticResource SNConverter}, ConverterParameter=1}">
                        <HyperlinkButton
                                    Content="{Binding DataLayer.GroupNames[0]}"
                                    Command="{Binding DataLayer.BackCommand}"
                                    CommandParameter="{Binding DataLayer.GroupNames[0]}"
                                    FontSize="15"/>
                        <TextBlock Text=" \ "/>
                    </StackPanel>
                    <StackPanel Visibility="{Binding DataLayer.Depth, Converter={StaticResource SNConverter}, ConverterParameter=2}">
                        <HyperlinkButton
                                    Content="{Binding DataLayer.GroupNames[1]}"
                                    Command="{Binding DataLayer.BackCommand}"
                                    CommandParameter="{Binding DataLayer.GroupNames[1]}"
                                    FontSize="15"/>
                        <TextBlock Text=" \ "/>
                    </StackPanel>
                    <StackPanel Visibility="{Binding DataLayer.Depth, Converter={StaticResource SNConverter}, ConverterParameter=1}">
                        <TextBlock Text="{Binding DataLayer.Current.Name}"/>
                        <TextBlock Text=" - "/>
                    </StackPanel>
                    <TextBlock>
                        <TextBlock.Inlines>
                            <Run Text="{Binding ElementName=cbAggregate, Path=SelectedItem.Key, Mode=OneWay}"/>
                            <Run Text=" By "/>
                            <Run Text="{Binding DataLayer.BindingX}" />
                        </TextBlock.Inlines>
                    </TextBlock>
                </StackPanel>
            </StackPanel>
            <Chart:C1FlexChart
                        x:Name="barChart"
                        DataContext="{Binding DataLayer}"
                        ToolTipContent="{}{name}"
                        Grid.Row="1"
                        ToolTip="{x:Null}"
                        ItemsSource="{Binding ItemsSource}"
                        BindingX="{Binding BindingX}"
                        Binding="{Binding Binding}"
                        Visibility="{Binding ElementName=cbChartTypes, Path=SelectedIndex, Converter={StaticResource ITVConverter}, ConverterParameter=0}"
                        >
                <Chart:Series/>
                <Chart:C1FlexChart.DataLabel>
                    <Chart:DataLabel Content="{}{value}" Position="Top"/>
                </Chart:C1FlexChart.DataLabel>
            </Chart:C1FlexChart>
            <Chart:C1FlexPie
                        x:Name="pieChart"
                        Grid.Row="1"
                        ToolTip="{x:Null}"
                        DataContext="{Binding DataLayer}"
                        ItemsSource="{Binding ItemsSource}"
                        BindingName="{Binding BindingX}"
                        Binding="{Binding Binding}"
                        Visibility="{Binding ElementName=cbChartTypes, Path=SelectedIndex, Converter={StaticResource ITVConverter}, ConverterParameter=1}"
                        >
                <Chart:C1FlexPie.DataLabel>
                    <Chart:PieDataLabel Content="{}{name}" Position="Center"/>
                </Chart:C1FlexPie.DataLabel>
            </Chart:C1FlexPie>
        </Grid>
    </Grid>
</Page>
