<UserControl x:Class="STPSLDemo.Page"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:STPSLDemo="clr-namespace:STPSLDemo" 
    Width="Auto" Height="Auto" Loaded="UserControl_Loaded">
    <UserControl.Resources>
        <Style x:Name="GroupboxStyle" TargetType="STPSLDemo:Groupbox">
            <Setter Property="BorderBrush" Value="DarkGray"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="Background" Value="White"/>
            <Setter Property="Padding" Value="6"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="STPSLDemo:Groupbox">
                        <Grid Background="{TemplateBinding Background}">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="*"/>
                            </Grid.RowDefinitions>
                            <Border BorderThickness="{TemplateBinding BorderThickness}" Grid.Row="1" Grid.RowSpan="2" BorderBrush="{TemplateBinding BorderBrush}" CornerRadius="3" />
                            <ContentPresenter Grid.Row="2" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" Margin="{TemplateBinding Padding}"/>
                            <ContentControl Margin="6,0,0,0" Grid.Row="0" Grid.RowSpan="2">
                                <Border Background="{TemplateBinding Background}">
                                    <ContentPresenter Margin="2,0,2,0" ContentTemplate="{TemplateBinding HeaderTemplate}" Content="{TemplateBinding Header}"/>
                                </Border>
                            </ContentControl>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>

    <Grid x:Name="LayoutRoot" Background="White" Margin="10,10,10,10">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="20"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="20"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="20"/>
        </Grid.ColumnDefinitions>

        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <TextBlock Text="Test Smart Thread Pool" FontSize="20" HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Column="0" Grid.ColumnSpan="5"/>

        <!--<TextBlock Text="STP Usage" HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Row="1" Grid.Column="1"/>-->
        <!--<TextBlock Text="STP History Usage" HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Row="1" Grid.Column="3"/>-->

        <STPSLDemo:Groupbox Header="STP Usage" Style="{StaticResource GroupboxStyle}" Grid.Row="2" Grid.Column="1" >
            <STPSLDemo:UsageControl x:Name="_usageControl" Value1="90" Value2="100" Width="36"/>
         </STPSLDemo:Groupbox>

        <STPSLDemo:Groupbox Header="STP History Usage" Style="{StaticResource GroupboxStyle}" Grid.Row="2" Grid.Column="3" >
            <STPSLDemo:UsageHistoryControl x:Name="_historyUsageControl"  Height="100" Width="400"/>
        </STPSLDemo:Groupbox>

        <StackPanel Grid.Row="4" Grid.Column="1" Grid.ColumnSpan="3" Orientation="Horizontal" Margin="0,10,0,0">
            <STPSLDemo:Groupbox Header="Work Items" Style="{StaticResource GroupboxStyle}">
                <Grid >
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="100"/>
                        <ColumnDefinition Width="50"/>
                    </Grid.ColumnDefinitions>

                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>

                    <TextBlock Text="Queued" HorizontalAlignment="Left" VerticalAlignment="Center" Grid.Row="0" Grid.Column="0" />
                    <TextBlock Text="Generated" HorizontalAlignment="Left" VerticalAlignment="Center" Grid.Row="1" Grid.Column="0"/>
                    <TextBlock Text="Completed" HorizontalAlignment="Left" VerticalAlignment="Center" Grid.Row="2" Grid.Column="0"/>

                    <TextBlock x:Name="_queuedWorkItems" Text="0" HorizontalAlignment="Right" VerticalAlignment="Center" Grid.Row="0" Grid.Column="1" />
                    <TextBlock x:Name="_generatedWorkItems" Text="0" HorizontalAlignment="Right" VerticalAlignment="Center" Grid.Row="1" Grid.Column="1"/>
                    <TextBlock x:Name="_completedWorkItems" Text="0" HorizontalAlignment="Right" VerticalAlignment="Center" Grid.Row="2" Grid.Column="1"/>


                </Grid>
            </STPSLDemo:Groupbox>
            <TextBlock Width="20"/>
            <STPSLDemo:Groupbox Header="Threads" Style="{StaticResource GroupboxStyle}">
                <Grid >
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="100"/>
                        <ColumnDefinition Width="50"/>
                    </Grid.ColumnDefinitions>

                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>

                    <TextBlock Text="In pool (Red)" HorizontalAlignment="Left" VerticalAlignment="Center" Grid.Row="0" Grid.Column="0" />
                    <TextBlock Text="Used (Green)" HorizontalAlignment="Left" VerticalAlignment="Center" Grid.Row="1" Grid.Column="0"/>

                    <TextBlock x:Name="_threadsInPool" Text="0" HorizontalAlignment="Right" VerticalAlignment="Center" Grid.Row="0" Grid.Column="1" />
                    <TextBlock x:Name="_threadsUsed" Text="0" HorizontalAlignment="Right" VerticalAlignment="Center" Grid.Row="1" Grid.Column="1"/>
                </Grid>
            </STPSLDemo:Groupbox>
        </StackPanel>


        <StackPanel Grid.Column="1" Grid.ColumnSpan="3" Grid.Row="5" Orientation="Vertical" HorizontalAlignment="Left" Margin="0,10,0,0">
            <StackPanel Orientation="Horizontal" Margin="0,10,0,0">
                <STPSLDemo:SpinButton x:Name="_spinMinThreads" ValueChanged="_spinMinThreads_ValueChanged" Maximum="25"/>
                <TextBlock Text="Minimum Threads" VerticalAlignment="Center" Margin="20,0,0,0"/>
            </StackPanel>
            <StackPanel Orientation="Horizontal" Margin="0,10,0,0">
                <STPSLDemo:SpinButton x:Name="_spinMaxThreads" ValueChanged="_spinMaxThreads_ValueChanged" Minimum="1" Maximum="25"/>
                <TextBlock Text="Maximum Threads" VerticalAlignment="Center" Margin="20,0,0,0"/>
            </StackPanel>
            <StackPanel Orientation="Horizontal" Margin="0,10,0,0">
                <STPSLDemo:SpinButton x:Name="_spinIdleTimeout" Minimum="1" Maximum="100"/>
                <TextBlock Text="Idle Timeout (Seconds)" VerticalAlignment="Center" Margin="20,0,0,0"/>
            </StackPanel>
            <StackPanel Orientation="Horizontal" Margin="0,10,0,0">
                <STPSLDemo:SpinButton x:Name="_spinInterval" ValueChanged="_spinInterval_ValueChanged" Minimum="0" Maximum="100000" Step="100"/>
                <TextBlock Text="Interval between work item production (milliseconds)" VerticalAlignment="Center" Margin="20,0,0,0"/>
            </StackPanel>
            <StackPanel Orientation="Horizontal" Margin="0,10,0,0">
                <STPSLDemo:SpinButton x:Name="_spinWorkItemTime" ValueChanged="_spinWorkItemTime_ValueChanged" Minimum="0" Maximum="100000" Step="100"/>
                <TextBlock Text="Work item consuming time (milliseconds)" VerticalAlignment="Center" Margin="20,0,0,0"/>
            </StackPanel>
        </StackPanel>

        <StackPanel Grid.Column="1" Grid.ColumnSpan="3" Grid.Row="6" Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,20,0,0">
            <Button x:Name="btnStart" Content="Start" Width="50" Click="Start_Click"/>
            <TextBlock Width="20"/>
            <Button x:Name="btnStop" Content="Stop" Width="50" Click="Stop_Click"  IsEnabled="False"/>

        </StackPanel>


    </Grid>
</UserControl>
