<UserControl
    x:Class="FlexChartExplorer.RangedHistogram"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:FlexChartExplorer"
    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"
    DataContext="{Binding RelativeSource={RelativeSource Mode=Self}}"
    mc:Ignorable="d">

    <Grid>
        <Grid.Resources>
            <local:EnumConverter x:Key="enumConverter" />
            <DataTemplate x:Key="cbModeTemplate">
                <TextBlock>
                    <TextBlock.Inlines>
                        <Run Text="Mode: "/>
                        <Run Text="{Binding .}"/>
                    </TextBlock.Inlines>
                </TextBlock>
            </DataTemplate>
            <Style TargetType="ComboBox">
                <Setter Property="VerticalAlignment" Value="Center" />
            </Style>
        </Grid.Resources>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition />
        </Grid.RowDefinitions>
        <StackPanel x:Name="stackPanel" Orientation="Horizontal">
            <StackPanel Orientation="Horizontal">
                <CheckBox Margin="10" x:Name="cbCategory" Content="By Category" VerticalAlignment="Center" IsChecked="False" Checked="cbCategory_Checked" Unchecked="cbCategory_Unchecked"/>
                <ComboBox Width="200" Margin="10" x:Name="cbMode" 
                      ItemsSource="{Binding DataContext.Mode}" 
                      ItemTemplate="{StaticResource cbModeTemplate}"
                      SelectedValue="{Binding ElementName=histogramSeries, Path=BinMode, Mode=TwoWay, Converter={StaticResource enumConverter}}"
                          SelectionChanged="cbMode_SelectionChanged">
                </ComboBox>
                <CheckBox Margin="10" x:Name="cbOverflow" Content="Overflow bin" VerticalAlignment="Center" IsChecked="False" Checked="cbOverflow_Checked"  Unchecked="cbOverflow_Unchecked"/>
                <TextBox x:Name="tbOverflow" IsEnabled="{Binding ElementName=cbOverflow, Path=IsChecked, Mode=TwoWay}" Width="100" VerticalAlignment="Center" TextAlignment="Right" PreviewTextInput="NumberValidationTextBox" TextChanged="tbOverflow_TextChanged"/>
                <CheckBox Margin="10" x:Name="cbUnderflow" Content="Underflow bin" VerticalAlignment="Center" IsChecked="False" Checked="cbUnderflow_Checked"  Unchecked="cbUnderflow_Unchecked"/>
                <TextBox x:Name="tbUnderflow" IsEnabled="{Binding ElementName=cbUnderflow, Path=IsChecked, Mode=TwoWay}" Width="100" VerticalAlignment="Center" TextAlignment="Right" PreviewTextInput="NumberValidationTextBox" TextChanged="tbUnderflow_TextChanged"/>
                <Label VerticalAlignment="Center">BinWidth :</Label>
                <TextBox x:Name="tbBinWidth" Width="100" VerticalAlignment="Center" TextAlignment="Right" PreviewTextInput="NumberValidationTextBox" TextChanged="tbBinWidth_TextChanged"/>
                <Label VerticalAlignment="Center">Number of Bins :</Label>
                <TextBox x:Name="tbBinNum" Width="100" VerticalAlignment="Center" TextAlignment="Right" PreviewTextInput="NumberValidationTextBox" TextChanged="tbBinNum_TextChanged"/>

            </StackPanel>
        </StackPanel>
        <Chart:C1FlexChart x:Name="flexChart" ChartType="RangedHistogram" ItemsSource="{Binding DataContext.Data}" Grid.Row="1" Binding="Value" Rendered="flexChart_Rendered">
            <Chart:RangedHistogram x:Name="histogramSeries" SeriesName="Frequency"/>
        </Chart:C1FlexChart>
    </Grid>
</UserControl>
