<Window
    x:Class="SelectorDragDropSamples.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:assist="clr-namespace:DragDropAssist;assembly=DragDropAssist"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:local="clr-namespace:SelectorDragDropSamples"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    x:Name="self"
    Title="MainWindow"
    Width="800"
    Height="450"
    mc:Ignorable="d">
    <Window.Resources>
        <LinearGradientBrush x:Key="TabItem_bg" StartPoint="0,0" EndPoint="0,1">
            <GradientStop Offset="0" Color="#1992DB" />
            <GradientStop Offset="0.1" Color="#DCEFF7" />
            <GradientStop Offset="1" Color="#DCEFF7" />
        </LinearGradientBrush>

        <Style x:Key="ListBoxItemStyle" TargetType="{x:Type ListBoxItem}">
            <Setter Property="Cursor" Value="Hand" />
            <Setter Property="Height" Value="40" />
            <Setter Property="VerticalAlignment" Value="Center" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ListBoxItem}">
                        <Border x:Name="ItemBorder" Width="{Binding Width, RelativeSource={RelativeSource TemplatedParent}}">
                            <TextBlock
                                x:Name="tbTitle"
                                Margin="5,0"
                                VerticalAlignment="Center"
                                Text="{Binding Name, Mode=OneTime}"
                                TextAlignment="Left"
                                TextTrimming="CharacterEllipsis"
                                TextWrapping="NoWrap" />
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="true">
                                <Setter TargetName="ItemBorder" Property="Background" Value="#DCEFF7" />
                                <Setter TargetName="tbTitle" Property="Foreground" Value="#1992DB" />
                            </Trigger>
                            <Trigger Property="IsSelected" Value="true">
                                <Setter TargetName="ItemBorder" Property="Background" Value="#1992DB" />
                                <Setter TargetName="tbTitle" Property="Foreground" Value="#DCEFF7" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <Style x:Key="TabItemStyle" TargetType="{x:Type TabItem}">
            <Setter Property="Background" Value="Transparent" />
            <Setter Property="FocusVisualStyle" Value="{x:Null}" />
            <Setter Property="Cursor" Value="Hand" />
            <Setter Property="HorizontalContentAlignment" Value="Stretch" />
            <Setter Property="VerticalContentAlignment" Value="Stretch" />
            <Setter Property="Padding" Value="0,5,10,0" />
            <Setter Property="Height" Value="20" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type TabItem}">
                        <Grid
                            x:Name="header"
                            MaxWidth="200"
                            Background="{TemplateBinding Background}">
                            <Rectangle
                                x:Name="Bd"
                                Margin="-1,0,0,0"
                                Fill="{StaticResource TabItem_bg}"
                                Visibility="Collapsed" />
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>
                                <TextBlock
                                    x:Name="mbTitle"
                                    Margin="18,4,18,0"
                                    HorizontalAlignment="Center"
                                    Text="{Binding ClassName}"
                                    TextWrapping="NoWrap"
                                    ToolTip="{Binding ClassName}" />
                            </Grid>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsSelected" Value="true">
                                <Setter Property="Foreground" Value="#005f98" />
                                <Setter TargetName="Bd" Property="Visibility" Value="Visible" />
                            </Trigger>
                            <MultiTrigger>
                                <MultiTrigger.Conditions>
                                    <Condition Property="IsSelected" Value="false" />
                                    <Condition Property="IsMouseOver" Value="true" />
                                </MultiTrigger.Conditions>
                                <Setter Property="Foreground" Value="#005f98" />
                            </MultiTrigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <DataTemplate x:Key="contentTemplate" DataType="{x:Type local:ClassInfo}">
            <ListBox
                assist:SelectorDragDropAttach.IsItemsDragDropEnabled="True"
                ItemContainerStyle="{StaticResource ListBoxItemStyle}"
                ItemsSource="{Binding Students}"
                ScrollViewer.CanContentScroll="False"
                VirtualizingPanel.IsVirtualizing="true"
                VirtualizingPanel.VirtualizationMode="Recycling" />
        </DataTemplate>
    </Window.Resources>
    <Grid>
        <TabControl
            assist:SelectorDragDropAttach.IsItemsDragDropEnabled="True"
            AlternationCount="{Binding ClassInfos.Count}"
            ContentTemplate="{StaticResource contentTemplate}"
            ItemContainerStyle="{StaticResource TabItemStyle}"
            ItemsSource="{Binding ClassInfos}"
            SelectedIndex="0" />
    </Grid>
</Window>
