<UserControl
    x:Class="FlexChartExplorer.Legend"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:Chart="http://schemas.componentone.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:FlexChartExplorer"
    DataContext="{Binding RelativeSource={RelativeSource Mode=Self}}"
    mc:Ignorable="d">

    <Grid>
        <Grid.Resources>
            <local:EnumConverter x:Key="enumConverter" />
            <local:MaxWidthConverter x:Key="maxWidthConverter" />
            <local:GroupCheckBoxVisibilityConverter x:Key="groupCheckBoxVisibilityConverter" />
            <DataTemplate x:Key="cbPositionTemplate">
                <TextBlock>
                    <TextBlock.Inlines>
                        <Run Text="Position: "/>
                        <Run Text="{Binding .}"/>
                    </TextBlock.Inlines>
                </TextBlock>
            </DataTemplate>
            <DataTemplate x:Key="cbOrientationTemplate">
                <TextBlock>
                    <TextBlock.Inlines>
                        <Run Text="Palette: "/>
                        <Run Text="{Binding .}"/>
                    </TextBlock.Inlines>
                </TextBlock>
            </DataTemplate>
            <DataTemplate x:Key="cbTextWrappingTemplate">
                <TextBlock>
                    <TextBlock.Inlines>
                        <Run Text="Wrapping: "/>
                        <Run Text="{Binding .}"/>
                    </TextBlock.Inlines>
                </TextBlock>
            </DataTemplate>
            <DataTemplate x:Key="cbMaxWidthTemplate">
                <TextBlock>
                    <TextBlock.Inlines>
                        <Run Text="Max Width: "/>
                        <Run Text="{Binding Name}"/>
                    </TextBlock.Inlines>
                </TextBlock>
            </DataTemplate>
            <Style TargetType="ComboBox">
                <Setter Property="VerticalAlignment" Value="Center" />
            </Style>
        </Grid.Resources>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition />
        </Grid.RowDefinitions>
        <StackPanel Orientation="Horizontal" Margin="10 0">
            <ComboBox Width="210" x:Name="cbPosition" 
                      ItemsSource="{Binding DataContext.LegendPosition}" 
                      ItemTemplate="{StaticResource cbPositionTemplate}"
                      SelectedValue="{Binding ElementName=flexChart, Path=LegendPosition, Mode=TwoWay, Converter={StaticResource enumConverter}}">
            </ComboBox>
            <ComboBox Width="200" Margin="10" x:Name="cbOrientation" 
                      ItemsSource="{Binding DataContext.LegendOrientation}" 
                      ItemTemplate="{StaticResource cbOrientationTemplate}"
                      SelectedValue="{Binding ElementName=flexChart, Path=LegendOrientation, Mode=TwoWay, Converter={StaticResource enumConverter}}">
            </ComboBox>
            <ComboBox Width="200" Margin="10" x:Name="cbTextWrapping" 
                      ItemsSource="{Binding DataContext.LegendTextWrapping}" 
                      ItemTemplate="{StaticResource cbTextWrappingTemplate}"
                      SelectedValue="{Binding ElementName=flexChart, Path=LegendTextWrapping, Mode=TwoWay, Converter={StaticResource enumConverter}}">
            </ComboBox>
            <ComboBox Width="200" Margin="10" x:Name="cbMaxWidth" 
                      ItemsSource="{Binding DataContext.LegendMaxWidth}" 
                      ItemTemplate="{StaticResource cbMaxWidthTemplate}"
                      SelectedIndex="0"
                      SelectedValue="{Binding ElementName=flexChart, Path=LegendMaxWidth, Mode=OneWayToSource, Converter={StaticResource maxWidthConverter}}"
                      >
            </ComboBox>
        </StackPanel>
        <Chart:C1FlexChart x:Name="flexChart" ItemsSource="{Binding DataContext.Data}" BindingX="Fruit" Grid.Row="1">
            <Chart:Series SeriesName="Label 1 (The quick brown fox jumps over the lazy dog)" Binding="March"/>
            <Chart:Series SeriesName="Label 2 (The quick brown fox jumps over the lazy dog)" Binding="April"/>
            <Chart:Series SeriesName="Label 3 (The quick brown fox jumps over the lazy dog)" Binding="May"/>
        </Chart:C1FlexChart>
    </Grid>
</UserControl>
