<UserControl
             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="clr-namespace:DrillDown"
             xmlns:c1="http://schemas.componentone.com/winfx/2006/xaml" 
             x:Class="DrillDown.BasicDrillDownDemo"
             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:ChartTypeConverter x:Key="chartTypeConverter"/>
            <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" VerticalAlignment="Stretch" >
                <Border Background="GhostWhite" 
                        BorderBrush="Gainsboro" 
                        BorderThickness="1"
                        >
                    <WrapPanel Margin="5">
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="GroupBy" FontWeight="Bold" VerticalAlignment="Center"/>
                            <ComboBox x:Name="cbGroupBy"
                                      SelectedValuePath="Value"
                                      DisplayMemberPath="Key"
                                      ItemsSource="{Binding Groups}"
                                      SelectedValue="{Binding GroupBy}"
                                      SelectedIndex="0"/>
                        </StackPanel>
                        <StackPanel>
                            <TextBlock Text="Aggregate Type" FontWeight="Bold" VerticalAlignment="Center"/>
                            <ComboBox x:Name="cbAggregate"
                                      DisplayMemberPath="Key"
                                      SelectedValuePath="Value"
                                      ItemsSource="{Binding Aggregates}"
                                      SelectedValue="{Binding Manager.AggregateType}"
                                      SelectedIndex="0"/>
                        </StackPanel>
                        <StackPanel>
                            <TextBlock Text="ChartType" FontWeight="Bold" VerticalAlignment="Center" />
                            <ComboBox x:Name="cbChartTypes"
                                        ItemsSource="{Binding ChartTypes}"
                                        SelectedValue="{Binding ElementName=flexChart,Path=ChartType,Mode=TwoWay,Converter={StaticResource chartTypeConverter}}"
                                        />
                        </StackPanel>
                        <StackPanel>
                            <CheckBox x:Name="chkEnableDrillDown" 
                                  Content="Enable DrillDown" 
                                  IsChecked="True" 
                                  VerticalAlignment="Center"
                                  Checked="OnCheckChanged" 
                                  Unchecked="OnCheckChanged"/>
                        </StackPanel>
                    </WrapPanel>
                </Border>
                <StackPanel Visibility="{Binding ElementName=cbChartTypes, Path=SelectedIndex, Converter={StaticResource ITVConverter}, ConverterParameter='0 1 2'}">
                    <StackPanel.Resources>
                        <Style TargetType="TextBlock">
                            <Setter Property="VerticalAlignment" Value="Center"/>
                            <Setter Property="FontSize" Value="15"/>
                        </Style>
                    </StackPanel.Resources>
                    <StackPanel Visibility="{Binding Manager.DrillDownLevel, Converter={StaticResource SNConverter}, ConverterParameter=1}">
                        <c1:C1HyperlinkButton
                                    Content="{Binding Manager.GroupNames[0]}"
                                    Command="{Binding Manager.BackCommand}"
                                    CommandParameter="{Binding Manager.GroupNames[0]}"
                                    FontSize="15"/>
                        <TextBlock Text=" \ "/>
                    </StackPanel>
                    <StackPanel Visibility="{Binding Manager.DrillDownLevel, Converter={StaticResource SNConverter}, ConverterParameter=2}">
                        <c1:C1HyperlinkButton
                                    Content="{Binding Manager.Parent.Name}"
                                    Command="{Binding Manager.BackCommand}"
                                    CommandParameter="{Binding DataLayer.GroupNames[1]}"
                                    FontSize="15"/>
                        <TextBlock Text=" \ "/>
                    </StackPanel>
                    <StackPanel Visibility="{Binding Manager.DrillDownLevel, Converter={StaticResource SNConverter}, ConverterParameter=1}">
                        <TextBlock Text="{Binding Manager.Current.Name}"/>
                        <TextBlock Text=" - "/>
                    </StackPanel>
                    <TextBlock>
                        <TextBlock.Inlines>
                            <Run Text="{Binding ElementName=cbAggregate, Path=SelectedItem.Key, Mode=OneWay}"/>
                            <Run Text=" by "/>
                            <Run Text="{Binding Manager.BindingX}" />
                        </TextBlock.Inlines>
                    </TextBlock>
                </StackPanel>
            </StackPanel>
            <c1:C1FlexChart
                        x:Name="flexChart"
                        DataContext="{Binding Manager}"
                        ToolTipContent="{}{y}"
                        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 1'}"
                        MouseLeftButtonDown="HandleNormalChartDrillDown">
                <c1:C1FlexChart.FooterStyle>
                    <c1:ChartStyle FontSize="16" FontWeight="Normal"/>
                </c1:C1FlexChart.FooterStyle>

                <c1:Series/>
                <c1:C1FlexChart.DataLabel>
                    <c1:DataLabel Content="{}{value}" Position="Top"/>
                </c1:C1FlexChart.DataLabel>
            </c1:C1FlexChart>
            <c1:C1FlexPie
                        x:Name="pieChart"
                        Grid.Row="1"
                        ToolTip="{x:Null}"
                        DataContext="{Binding Manager}"
                        ItemsSource="{Binding ItemsSource}"
                        BindingName="{Binding BindingX}"
                        Binding="{Binding Binding}"
                        Visibility="{Binding ElementName=cbChartTypes, Path=SelectedIndex, Converter={StaticResource ITVConverter}, ConverterParameter=2}"
                        MouseLeftButtonDown="HandleNormalChartDrillDown">
                <c1:C1FlexPie.FooterStyle>
                    <c1:ChartStyle FontSize="16" FontWeight="Normal"/>
                </c1:C1FlexPie.FooterStyle>

                <c1:C1FlexPie.DataLabel>
                    <c1:PieDataLabel Content="{}{name}" Position="Center"/>
                </c1:C1FlexPie.DataLabel>
            </c1:C1FlexPie>
        </Grid>
    </Grid>
</UserControl>
