<UserControl xmlns:c1="using:C1.Xaml"  xmlns:c1chart="using:C1.Xaml.Chart" 
    x:Class="DrillDown.DrillDown"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:DrillDown"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="480"
    d:DesignWidth="600">

    <Grid Margin="10">
        <Grid.Resources>
            <local:IntToVisibilityConverter x:Key="ITVConverter"/>
            <local:ShowNavigateConverter x:Key="SNConverter"/>
            <local:Select2VisibilityConverter 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>
        <c1:C1TabControl>
            <c1:C1TabItem Header="Pie/Column">
                <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 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>
                    <c1chart: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}"
                        >
                        <c1chart:Series/>
                        <c1chart:C1FlexChart.DataLabel>
                            <c1chart:DataLabel Content="{}{value}" Position="Top"/>
                        </c1chart:C1FlexChart.DataLabel>
                    </c1chart:C1FlexChart>
                    <c1chart: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}"
                        >
                        <c1chart:C1FlexPie.DataLabel>
                            <c1chart:PieDataLabel Content="{}{name}" Position="Center"/>
                        </c1chart:C1FlexPie.DataLabel>
                    </c1chart:C1FlexPie>
                </Grid>
            </c1:C1TabItem>
            <c1:C1TabItem Header="Sunburst" x:Name="tabSunburst">
                <Grid Margin="10">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition/>
                    </Grid.RowDefinitions>
                    <TextBlock Text="Click a slice to drill down into the details, or click on the back hyperlink to return to a higher level."/>
                    <c1chart:C1Sunburst
                        x:Name="sunburst"
                        Grid.Row="1"
                        ToolTip="{x:Null}"
                        DataContext="{Binding SunburstDataLayer}"
                        ItemsSource="{Binding ItemsSource}"
                        Binding="{Binding Binding}"
                        BindingName="{Binding BindingX}"
                        Rendering="HandleSunburstRendering"
                        InnerRadius="0.2"
                        ChildItemsPath="Items"
                        Palette="Custom"
                        CustomPalette="{Binding CustomPalette}"
                        Visibility="{Binding ElementName=tabSunburst, Path=IsSelected, Converter={StaticResource Select2VisibilityConverter}}"
                        >
                        <c1chart:C1Sunburst.DataLabel>
                            <c1chart:PieDataLabel Content="{}{name}" Position="Center"/>
                        </c1chart:C1Sunburst.DataLabel>
                    </c1chart:C1Sunburst>
                </Grid>
            </c1:C1TabItem>
        </c1:C1TabControl>
    </Grid>
</UserControl>
