<UserControl x:Class="PDF_Office.Views.BOTA.OutLineControl"
             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:PDF_Office.Views.BOTA"
             xmlns:customcontrol="clr-namespace:PDF_Office.CustomControl"
             xmlns:model="clr-namespace:PDF_Office.Model.BOTA"
             xmlns:bota="clr-namespace:PDF_Office.ViewModels.BOTA" d:DataContext="{d:DesignInstance Type=bota:OutLineControlViewModel}"
             mc:Ignorable="d" 
             x:Name="ttt">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/PDF Office;component/Styles/OutLineItemStyle.xaml"/>
            </ResourceDictionary.MergedDictionaries>

        </ResourceDictionary>
    </UserControl.Resources>
    <Grid  Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="40"/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <Grid x:Name="Header">
            <TextBlock x:Name="TxtTitle" Margin="12,0,0,0" HorizontalAlignment="Left"
                    VerticalAlignment="Center" FontSize="18" FontWeight="SemiBold" Text="Outline" />
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
                <customcontrol:PathButton
            x:Name="BtnAdd"
            Click="BtnAdd_Click"
            Height="24" Width="24"  IconHeight="20"  IconWidth="20" 
            Icon="{StaticResource Ic_AddButtonPath}"  IconFill="Red"
            IconPress="{StaticResource Ic_AddButtonPath}" IconPressFill="#C04CF8"
            IconMouseOver="{StaticResource Ic_AddButtonPath}" IconMouseOverFill="#C04CF8" />
                <customcontrol:PathButton
            x:Name="BtnMore"
            Click="BtnMore_Click"
            Height="24" Width="24"  IconHeight="20"  IconWidth="20" 
            Icon="{StaticResource Ic_MoreButtonPath}"  IconFill="Red"
            IconPress="{StaticResource Ic_MoreButtonPath}" IconPressFill="#C04CF8"
            IconMouseOver="{StaticResource Ic_MoreButtonPath}" IconMouseOverFill="#C04CF8" >
                    <customcontrol:PathButton.ContextMenu>
                        <ContextMenu
                            Name="MenuMore">
                            <ContextMenu.ItemContainerStyle>
                                <Style TargetType="MenuItem">
                                    <Setter Property="Padding" Value="-25,7,-40,7" />
                                    <Setter Property="VerticalContentAlignment" Value="Center" />
                                </Style>
                            </ContextMenu.ItemContainerStyle>
                            <MenuItem
                                Name="MenuDeleteAll"
                                Command="{Binding DeleteAllCommand}"
                                Header="Delete All Outline" />
                            <MenuItem
                                Name="MenuExpandAll"
                                Command="{Binding ExpandAllCommand}"
                                CommandParameter="{Binding Outlinelist}"
                                Header="一键展开" />
                            <MenuItem
                                Name="MenuCollapseAll"
                               Command="{Binding CollapseAllCommand}"
                                CommandParameter="{Binding Outlinelist}"
                                Header="一键折叠" />
                        </ContextMenu>
                    </customcontrol:PathButton.ContextMenu>
                </customcontrol:PathButton>
            </StackPanel>
        </Grid>

        <StackPanel Margin="10,0" x:Name="FirstOulineLine" Orientation="Horizontal"  VerticalAlignment="Bottom" Visibility="{Binding IsInsertHead,Converter={StaticResource BoolToVisible}}">
            <Ellipse Width="8" Height="8" Fill="White" Stroke="#FF0078D7" StrokeThickness="1.5" HorizontalAlignment="Stretch" VerticalAlignment="Bottom"/>
            <Rectangle Margin="-1,0,0,2" Width="{Binding ElementName=Header,Path=ActualWidth}" HorizontalAlignment="Stretch" Height="1.5" StrokeDashArray="2" VerticalAlignment="Bottom" Fill="#FF0078D7"/>
        </StackPanel>
        <Grid Grid.Row="1"
               DragOver="Grid_DragOver"
              DragLeave="Grid_DragLeave">
            <TreeView x:Name="OutlineView" Grid.Row="1" ItemsSource="{Binding Outlinelist}" 
                BorderThickness="0" AllowDrop="True"
                VirtualizingPanel.ScrollUnit="Pixel"
                Drop="OutlineView_Drop"
                PreviewMouseMove="OutlineView_PreviewMouseMove" 
                PreviewMouseLeftButtonUp="OutlineView_PreviewMouseLeftButtonUp"
                PreviewMouseDoubleClick="OutlineView_PreviewMouseDoubleClick"
                ScrollViewer.HorizontalScrollBarVisibility="Disabled">
                <TreeView.ItemTemplate>
                    <HierarchicalDataTemplate   DataType="{x:Type model:OutlineNode}" ItemsSource="{Binding Path=Chlidlist}">
                        <Grid>
                            <Grid.ContextMenu>
                                <ContextMenu>
                                    <MenuItem x:Name="AddMenu" Click="AddMenu_Click" Header="添加条目"/>
                                    <MenuItem x:Name="AddChlidMenu" Click="AddChlidMenu_Click"  Header="添加子条目"/>
                                    <MenuItem x:Name="AddParentMenu" Click="AddParentMenu_Click" Header="添加上一级条目" IsEnabled="{Binding CanAddParent}"/>

                                    <MenuItem x:Name="DeleteMenu" Click="DeleteMenu_Click" Header="删除"/>

                                    <MenuItem x:Name="RenameMenu" Click="RenameMenu_Click" Header="重命名"/>
                                    <MenuItem x:Name="ChangeDestinationMenu" Click="ChangeDestinationMenu_Click" Header="更改目标位置"/>

                                    <MenuItem x:Name="UpgradeMenu" Click="UpgradeMenu_Click" Header="升级" IsEnabled="{Binding CanUp}"/>
                                    <MenuItem x:Name="DowngradeMenu" Click="DowngradeMenu_Click" Header="降级" IsEnabled="{Binding CanDown}"/>
                                </ContextMenu>
                            </Grid.ContextMenu>
                            <Grid x:Name="ContentPanel" >
                                <Grid.ToolTip>
                                    <ToolTip  Opened="ToolTip_Opened" Closed="ToolTip_Closed" >
                                        <customcontrol:CustomImageControl Width="400" Height="120" />
                                    </ToolTip>
                                </Grid.ToolTip>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition />
                                    <ColumnDefinition Width="auto" />
                                </Grid.ColumnDefinitions>
                                <TextBlock x:Name="Content" Text="{Binding Outline.Title}" Visibility="{Binding IsReName,Mode=TwoWay}" VerticalAlignment="Center" TextTrimming="CharacterEllipsis"/>
                                <TextBlock x:Name="PageIndex" Grid.Column="1" HorizontalAlignment="Right"  VerticalAlignment="Center" Text="{Binding PageIndex}"/>
                            </Grid>

                            <StackPanel  Orientation="Horizontal" HorizontalAlignment="Stretch" Visibility="{Binding IsInsertNextLayer, Converter={StaticResource BoolToVisible}}" >
                                <Ellipse Margin="0,0,0,0" Width="8" Height="8" Fill="White" Stroke="#FF0078D7"  StrokeThickness="1.5" VerticalAlignment="Bottom"/>
                                <Line Margin="-1,0,0,2" X1="0"  X2="{Binding ElementName=ContentPanel,Path=ActualWidth}" HorizontalAlignment="Stretch" StrokeThickness="1.5" StrokeDashArray="2" Stroke="#FF0078D7" VerticalAlignment="Bottom"/>
                            </StackPanel>
                            <Grid x:Name="RenameGrid"
                                  LostFocus="RenameGrid_LostFocus"
                                  Visibility="{Binding ElementName=Content,Path=Visibility,Mode=TwoWay,Converter={StaticResource UnVisivleConvert}}">
                                <TextBox x:Name="ReName" HorizontalAlignment="Left" VerticalAlignment="Center" 
                                         IsVisibleChanged="ReName_IsVisibleChanged"/>
                            </Grid>
                        </Grid>
                    </HierarchicalDataTemplate>
                </TreeView.ItemTemplate>
                <TreeView.ItemContainerStyle>
                    <Style BasedOn="{StaticResource OutLineItemStyle}" TargetType="TreeViewItem">
                        <EventSetter Event="PreviewMouseLeftButtonUp" Handler="TreeViewItem_PreviewMouseLeftButtonUp"/>
                    </Style>
                </TreeView.ItemContainerStyle>
            </TreeView>
        </Grid>
    </Grid>
</UserControl>
