<UserControl x:Class="Compdfkit_Tools.PDFControl.CPDFPageEditControl"
             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:Compdfkit_Tools.PDFControl"
              Loaded="UserControl_Loaded"
             Unloaded="UserControl_Unloaded"
             PreviewMouseWheel ="UserControl_PreviewMouseWheel"
             IsVisibleChanged="PageEditor_IsVisibleChanged"
             PreviewKeyDown="UserControl_KeyDown"
             MouseEnter="UserControl_MouseEnter"
             xmlns:wpftk="clr-namespace:WpfToolkit.Controls;assembly=VirtualizingWrapPanel"
             mc:Ignorable="d" 
             SizeChanged="UserControl_SizeChanged"
             xmlns:cpdfcommon="clr-namespace:Compdfkit_Tools.Common"
             d:DesignHeight="450" d:DesignWidth="800">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="../../Asset/Styles/ListBoxItemStyle.xaml"></ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>
            <ContextMenu x:Key="FlyoutMenu" FontSize="14" Loaded="ContextMenu_Loaded">
                <ContextMenu.ItemContainerStyle>
                    <Style TargetType="{x:Type MenuItem}">
                        <Setter Property="Padding" Value="0,8,0,8"/>
                        <Setter Property="VerticalContentAlignment" Value="Center"/>
                    </Style>
                </ContextMenu.ItemContainerStyle>
                <MenuItem Name="LeftRotate"  Header="Left Rotate" IsEnabled="True" Click="Rotate_Click"></MenuItem>
                <MenuItem Name="RightRotate" Header="Right Rotate" IsEnabled="True" Click="Rotate_Click"></MenuItem>
                <MenuItem Name="Copy" Header="Copy" IsEnabled="True" Click="Copy_Click"></MenuItem>
                <MenuItem Name="Delete" Header="Delete" Click="Delete_Click"></MenuItem>
            </ContextMenu>
            <RoutedUICommand x:Key="LeftRotate" Text="Left rotate"/>
            <RoutedUICommand x:Key="RightRotate" Text="Right rotate"/>
            <RoutedUICommand x:Key="Delete" Text="Delete"/>
            <RoutedUICommand x:Key="Copy" Text="Copy"/>

            <Grid x:Key="bookMarkIco">
                <Polygon Fill="#FFBB00" Points="16.75 1.25 3.25 1.25 3.25 19.4013878 10 14.902 16.75 19.4013878" Visibility="Visible"/>
            </Grid>
        </ResourceDictionary>
    </UserControl.Resources>

    <UserControl.InputBindings>
        <KeyBinding Gesture="Ctrl+L" Command="{StaticResource LeftRotate}" />
        <KeyBinding Gesture="Ctrl+R" Command="{StaticResource RightRotate}" />
        <KeyBinding Gesture="Ctrl+C" Command="{StaticResource Copy}" />
        <KeyBinding Gesture="Delete" Command="{StaticResource Delete}" />
    </UserControl.InputBindings>

    <UserControl.CommandBindings>
        <CommandBinding Command="{StaticResource LeftRotate}" Executed="CommandBinding_Executed_LeftRotate"/>
        <CommandBinding Command="{StaticResource RightRotate}" Executed="CommandBinding_Executed_RightRotate"/>
        <CommandBinding Command="{StaticResource Delete}" Executed="CommandBinding_Executed_Delete"/>
        <CommandBinding Command="{StaticResource Copy}" Executed="CommandBinding_Executed_Copy"/>
    </UserControl.CommandBindings>
    <Grid>
        <Grid Name="PageGrid"  DragOver="Grid_DragOver"  PreviewDragEnter="PageGrid_PreviewDragEnter" >
            <ListBox Name="PageEditListBox"   SelectionChanged="PageEditListBox_SelectionChanged" 
                 SelectionMode="Extended"  ScrollViewer.CanContentScroll="True"
                 AllowDrop="True"
                 ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                 ScrollViewer.ScrollChanged="PageEditListBox_ScrollChanged"
                 ScrollBar.Scroll="PageEditListBox_Scroll"
                 KeyUp="PageEditListBox_KeyUp"
                 PreviewMouseMove="PageEditListBox_PreviewMouseMove"
                 PreviewMouseLeftButtonDown="PageEditListBox_PreviewMouseLeftButtonDown"
                 MouseLeftButtonUp="PageEditListBox_MouseLeftButtonUp"
                 Drop="PageEditListBox_Drop"
                 SizeChanged="PageEditListBox_SizeChanged"
                 Background="Transparent"
                 BorderThickness="0"
                 VirtualizingPanel.VirtualizationMode="Standard"
                 VirtualizingPanel.CacheLengthUnit="Page"
                 VirtualizingPanel.CacheLength="1"
                 VirtualizingPanel.ScrollUnit="Pixel"  
            >

                <ListBox.ItemContainerStyle>
                    <Style TargetType="{x:Type ListBoxItem}">
                        <Setter Property="HorizontalContentAlignment" Value="Left"/>
                        <Setter Property="VerticalContentAlignment" Value="Center"/>
                        <EventSetter Event="DragLeave" Handler="ListBoxItem_DragLeave"/>
                        <Setter Property="ContextMenu" Value="{StaticResource FlyoutMenu}"/>
                        <EventSetter Event="PreviewMouseDoubleClick" Handler="ListBoxItem_PreviewMouseDoubleClick"/>
                        <EventSetter Event="PreviewMouseLeftButtonDown" Handler="ListBoxItem_PreviewMouseLeftButtonDown"/>
                        <Setter Property="Template" Value="{DynamicResource ListBoxItemControlTemplate}"/>
                        <Setter Property="Width" Value="auto"/>
                    </Style>
                </ListBox.ItemContainerStyle>
                <ListBox.ItemsPanel>
                    <ItemsPanelTemplate>
                        <wpftk:VirtualizingWrapPanel  Margin="0 0 0 0" Name="PART_Panel" Background="White"></wpftk:VirtualizingWrapPanel>
                    </ItemsPanelTemplate>
                </ListBox.ItemsPanel>
            </ListBox>

            <ProgressBar Name="progress" Height="15" Width="400" IsIndeterminate="True" Visibility="Collapsed"/>
            <Border Name="tip" Visibility="Collapsed" CornerRadius="4" Background="#89000000" Grid.Row="1"  HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="0,0,0,150">
                <TextBlock x:Name="PageViewTipText" Margin="12,4" Foreground="White" FontSize="14" Padding="4 2 4 2"/>
            </Border> 
            <Line Name="MidLane" StrokeStartLineCap="Triangle" StrokeEndLineCap="Triangle"  Visibility="Collapsed"  AllowDrop="True" Drop="MidLane_Drop"  X1="20" X2="20" Y1="0" Y2="150" Stroke="#FF477EDE" StrokeThickness="5"/>
 
            <Image Name="ShadowPicture" Opacity="0.8" Visibility="{Binding ElementName=MidLane,Path=Visibility}" AllowDrop="True"  Drop="ShadowPicture_Drop" RenderOptions.BitmapScalingMode="HighQuality" UseLayoutRounding="True"  HorizontalAlignment="Left" VerticalAlignment="Top"/>

            <Rectangle Name="ChooseRect" VerticalAlignment="Top" HorizontalAlignment="Left" Stroke="#AACCEE" StrokeThickness ="2" Fill ="#AACCEE" Opacity="0.3"/>
        </Grid>
        <Border x:Name="AlertBorder" Height="30" Width="auto" Background="#CE1A1A1A" VerticalAlignment="Top" HorizontalAlignment="Center" CornerRadius="4" Margin="10"  Visibility="Collapsed">
            <TextBlock x:Name="AlertTextBlock" Foreground="#FFFFFF" Text="Empty" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="10,5,10,5"></TextBlock>
        </Border>
    </Grid>

</UserControl>
