Explorar o código

大纲-除添加大纲以外的相关功能

zhuyi %!s(int64=2) %!d(string=hai) anos
pai
achega
e6609ccc6b

+ 2 - 2
PDF Office/CustomControl/PlayViewEdit.cs

@@ -15,11 +15,11 @@ using System.Windows.Shapes;
 
 namespace PDF_Office.CustomControl
 {
-    internal class PlayViewEdit : FrameworkElement
+    internal class CustomImageControl : FrameworkElement
     {
         private DrawingVisual PresentChild { get; set; }
         private DrawingContext DrawDC { get; set; }
-        public PlayViewEdit()
+        public CustomImageControl()
         {
             PresentChild = new DrawingVisual();
             AddVisualChild(PresentChild);

+ 94 - 1
PDF Office/Model/BOTA/OutlineNode.cs

@@ -6,6 +6,7 @@ using System.Collections.ObjectModel;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using System.Windows;
 
 namespace PDF_Office.Model.BOTA
 {
@@ -80,6 +81,9 @@ namespace PDF_Office.Model.BOTA
             }
         }
 
+        /// <summary>
+        /// 当前节点展开状态
+        /// </summary>
         private bool isExpanded = false;
 
         public bool IsExpanded
@@ -91,7 +95,64 @@ namespace PDF_Office.Model.BOTA
             }
         }
 
-        private string pageIndex ="";
+        private bool isSelected;
+
+        public bool IsSelected
+        {
+            get { return isSelected; }
+            set
+            {
+                SetProperty(ref isSelected, value);
+            }
+        }
+
+        private bool canDown = true;
+
+        public bool CanDown
+        {
+            get { return canDown; }
+            set
+            {
+                SetProperty(ref canDown, value);
+            }
+        }
+
+        private bool canUp = true;
+
+        public bool CanUp
+        {
+            get { return canUp; }
+            set
+            {
+                SetProperty(ref canUp, value);
+            }
+        }
+
+        private bool canAddParent = true;
+
+        public bool CanAddParent
+        {
+            get { return canAddParent; }
+            set
+            {
+                SetProperty(ref canAddParent, value);
+            }
+        }
+
+        private Visibility isReName=Visibility.Visible;
+
+        public Visibility IsReName
+        {
+            get { return isReName; }
+            set
+            {
+                SetProperty(ref isReName, value);
+            }
+        }
+
+
+
+        private string pageIndex = "";
 
         public string PageIndex
         {
@@ -102,6 +163,38 @@ namespace PDF_Office.Model.BOTA
             }
         }
 
+        private double positionX;
+
+        public double PositionX
+        {
+            get { return positionX; }
+            set
+            {
+                SetProperty(ref positionX, value);
+            }
+        }
+
+        private double positionY;
+
+        public double PositionY
+        {
+            get { return positionY; }
+            set
+            {
+                SetProperty(ref positionY, value);
+            }
+        }
+
+        private double zoom;
+
+        public double Zoom
+        {
+            get { return zoom; }
+            set
+            {
+                SetProperty(ref zoom, value);
+            }
+        }
 
     }
 }

+ 1 - 1
PDF Office/PDF Office.csproj

@@ -199,6 +199,7 @@
       <DependentUpon>CommonWritableComboBox.xaml</DependentUpon>
     </Compile>
     <Compile Include="CustomControl\CustomIconToggleBtn.cs" />
+    <Compile Include="CustomControl\CustomImageControl.cs" />
     <Compile Include="CustomControl\DialogContent.cs" />
     <Compile Include="CustomControl\IconAndTextTabItem.cs" />
     <Compile Include="CustomControl\ListBoxItemToolBar.cs" />
@@ -210,7 +211,6 @@
       <DependentUpon>PageTurningPreview.xaml</DependentUpon>
     </Compile>
     <Compile Include="CustomControl\PathButton.cs" />
-    <Compile Include="CustomControl\PlayViewEdit.cs" />
     <Compile Include="CustomControl\SystemControl\CustomCommandAction .cs" />
     <Compile Include="CustomControl\SystemControl\RoutedEventTrigger.cs" />
     <Compile Include="CustomControl\ToastControl.xaml.cs">

+ 1 - 0
PDF Office/Styles/OutLineItemStyle.xaml

@@ -64,6 +64,7 @@
 
     <Style x:Key="OutLineItemStyle" TargetType="{x:Type TreeViewItem}">
         <Setter Property="IsExpanded" Value="{Binding IsExpanded,Mode=TwoWay}"/>
+        <Setter Property="IsSelected" Value="{Binding IsSelected,Mode=TwoWay}"/>
         <Setter Property="Background" Value="Transparent" />
         <Setter Property="HorizontalContentAlignment" Value="Center" />
         <Setter Property="VerticalContentAlignment" Value="Center" />

+ 181 - 16
PDF Office/ViewModels/BOTA/OutLineControlViewModel.cs

@@ -4,6 +4,7 @@ using ComPDFKit.PDFPage;
 using ComPDFKitViewer.PdfViewer;
 using PDF_Office.Model;
 using PDF_Office.Model.BOTA;
+using Prism.Commands;
 using Prism.Mvvm;
 using Prism.Regions;
 using System;
@@ -13,6 +14,7 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using System.Windows;
+using System.Windows.Controls;
 using System.Windows.Media;
 using System.Windows.Media.Imaging;
 
@@ -20,6 +22,10 @@ namespace PDF_Office.ViewModels.BOTA
 {
     class OutLineControlViewModel : BindableBase, INavigationAware
     {
+        //缩略图相关全局变量,减少内存申请次数
+        private WriteableBitmap WirteBitmap;
+        private byte[] bmpData;
+
         private CPDFViewer PDFViewer;
 
         public ObservableCollection<OutlineNode> Outlinelist { get; set; }
@@ -35,9 +41,25 @@ namespace PDF_Office.ViewModels.BOTA
             }
         }
 
+        private bool isOnDrop = false;
+
+        public bool IsOnDrop
+        {
+            get { return isOnDrop; }
+            set { isOnDrop = value; }
+        }
+
+        public DelegateCommand<ObservableCollection<OutlineNode>> CollapseAllCommand { get; set; }
+        public DelegateCommand<ObservableCollection<OutlineNode>> ExpandAllCommand { get; set; }
+        public DelegateCommand DeleteAllCommand { get; set; }
+        public DelegateCommand<OutlineNode> DowngradeCommand { get; set; }
+
         public OutLineControlViewModel()
         {
             Outlinelist = new ObservableCollection<OutlineNode>();
+            DeleteAllCommand = new DelegateCommand(DeleteAll);
+            CollapseAllCommand = new DelegateCommand<ObservableCollection<OutlineNode>>(CollapseAll);
+            ExpandAllCommand = new DelegateCommand<ObservableCollection<OutlineNode>>(ExpandAll);
         }
 
         public bool IsNavigationTarget(NavigationContext navigationContext)
@@ -61,7 +83,7 @@ namespace PDF_Office.ViewModels.BOTA
             Outlinelist.Clear();
             foreach (CPDFOutline item in datasource)
             {
-                OutlineNode dto = ConvertCPDFToOutlineNode(item, null,false);
+                OutlineNode dto = ConvertCPDFToOutlineNode(item, null, false);
                 if (dto != null)
                 {
                     Outlinelist.Add(dto);
@@ -94,6 +116,7 @@ namespace PDF_Office.ViewModels.BOTA
 
             PDFViewer.UndoManager.CanSave = true;
         }
+
         public bool SetTitle(CPDFOutline cPDFOutline, string Title)
         {
             if (cPDFOutline == null)
@@ -103,6 +126,87 @@ namespace PDF_Office.ViewModels.BOTA
             return cPDFOutline.SetTitle(Title);
         }
 
+        public void GoToPage(TreeViewItem treeViewItem)
+        {
+            OutlineNode outline = treeViewItem.DataContext as OutlineNode;
+            if (outline == null)
+            {
+                return;
+            }
+            CPDFAction action = outline.Outline.GetAction();
+            if (action != null && action.ActionType != C_ACTION_TYPE.ACTION_TYPE_UNKNOWN)
+                PDFViewer.ProcessAction(action);
+            else
+            {
+                Size size = PDFViewer.Document.GetPageSize(Convert.ToInt32(outline.PageIndex) - 1);
+                PDFViewer.GoToPage(Convert.ToInt32(outline.PageIndex) - 1, new Point(size.Width - outline.PositionX, size.Height - outline.PositionY));
+            }
+        }
+
+        public void CollapseAll(ObservableCollection<OutlineNode> outlineNodes)
+        {
+            foreach (var item in outlineNodes)
+            {
+                item.IsExpanded = false;
+                if (item.Chlidlist.Count > 0)
+                {
+                    CollapseAll(item.Chlidlist);
+                }
+            }
+        }
+
+        public void ExpandAll(ObservableCollection<OutlineNode> outlineNodes)
+        {
+            foreach (var item in outlineNodes)
+            {
+                item.IsExpanded = true;
+                if (item.Chlidlist.Count > 0)
+                {
+                    ExpandAll(item.Chlidlist);
+                }
+            }
+        }
+
+        public void DeleteAll()
+        {
+            foreach (var item in Outlinelist)
+            {
+                item.Outline.RemoveFromParent(this.PDFViewer.Document);
+            }
+            Updata(false);
+        }
+
+        public void Downgrade(OutlineNode outline)
+        {
+            if (outline != null)
+            {
+                CPDFOutline parent = outline.Outline.GetParent();
+                int index = GetOutlinesIndexFormParent(parent, outline.Outline);
+                CPDFOutline newparent = parent.ChildList[index - 2];
+                int insertindex = newparent.ChildList.Count;
+                newparent.MoveChildAtIndex(PDFViewer.Document, outline.Outline, insertindex);
+                Updata(false);
+            }
+        }
+        
+        public void Upgrade(OutlineNode outline)
+        {
+            if (outline != null)
+            {
+                CPDFOutline parent = outline.Outline.GetParent();
+                CPDFOutline newparent = parent.GetParent();
+                int index = GetOutlinesIndexFormParent(parent.GetParent(), parent);
+                newparent.MoveChildAtIndex(PDFViewer.Document, outline.Outline, index);
+                Updata(false);
+            }
+        }
+
+        public void RemoveOutline(OutlineNode outline)
+        {
+            outline.Outline.RemoveFromParent(PDFViewer.Document);
+            Updata(false);
+        }
+
         /// <summary>
         /// 插入大纲到目标节点
         /// </summary>
@@ -153,27 +257,42 @@ namespace PDF_Office.ViewModels.BOTA
             }
             return Tag;
         }
-        public WriteableBitmap WirteBitmap;
-        byte[] bmpData;
-        public WriteableBitmap LoadPreview()
-        {
-            CPDFPage page = PDFViewer.Document.PageAtIndex(1);
-            Size size = PDFViewer.Document.GetPageSize(1);
 
+        /// <summary>
+        /// 获取对应大纲所需的缩略图数据
+        /// </summary>
+        public WriteableBitmap LoadPreview(OutlineNode outlineNode)
+        {
+            CPDFPage page = PDFViewer.Document.PageAtIndex(Convert.ToInt32(outlineNode.PageIndex) - 1);
+            Size size = PDFViewer.Document.GetPageSize(Convert.ToInt32(outlineNode.PageIndex) - 1);
+            Point zoomXY = new Point(outlineNode.PositionX * outlineNode.Zoom, outlineNode.PositionY * outlineNode.Zoom);
+            //数据校验,暂不确定SDK会不会给垃圾值。说是从底层返回的。
+            if (zoomXY.X > size.Width || zoomXY.X < 0)
+            {
+                zoomXY.X = 0;
+            }
+            if (zoomXY.Y > size.Height || zoomXY.Y < 0)
+            {
+                zoomXY.Y = 0;
+            }
+            Size zoomSize = new Size((int)(size.Width * outlineNode.Zoom), (int)(size.Height * outlineNode.Zoom));
+            bmpData = new byte[(int)(zoomSize.Width * zoomSize.Height * 4)];
+            WirteBitmap = new WriteableBitmap((int)zoomSize.Width, (int)zoomSize.Height, 96, 96, PixelFormats.Bgra32, null);
 
-            bmpData = new byte[(int)(size.Width * size.Height * 4)];
-            WirteBitmap = new WriteableBitmap((int)size.Width, (int)size.Height, 96, 96, PixelFormats.Bgra32, null);
-
-            if (page.IsValid())
+            if (!page.IsValid())
             {
-                page.RenderPageBitmapWithMatrix((float)0.5, new Rect(0, 0, (int)size.Width, (int)size.Height), 0xFFFFFFFF, bmpData, 1, true);
+                return null;
             }
-            WirteBitmap.WritePixels(new Int32Rect(0, 0, (int)size.Width, (int)size.Height), bmpData, WirteBitmap.BackBufferStride, 0);
+            page.RenderPageBitmapWithMatrix((float)outlineNode.Zoom, new Rect(zoomXY.X, zoomXY.Y, zoomSize.Width, zoomSize.Height), 0xFFFFFFFF, bmpData, 1, true);
+            WirteBitmap.WritePixels(new Int32Rect(0, 0, (int)zoomSize.Width, (int)zoomSize.Height), bmpData, WirteBitmap.BackBufferStride, 0);
             WirteBitmap.Freeze();
             return WirteBitmap;
         }
 
-        private OutlineNode ConvertCPDFToOutlineNode(CPDFOutline outline, OutlineNode parent,bool IsMoveData)
+        /// <summary>
+        /// 将PDF对象转换为自定义数据类型,并存储
+        /// </summary>
+        private OutlineNode ConvertCPDFToOutlineNode(CPDFOutline outline, OutlineNode parent, bool IsMoveData)
         {
             OutlineNode node = new OutlineNode();
             if (outline != null)
@@ -181,7 +300,10 @@ namespace PDF_Office.ViewModels.BOTA
                 node.IsInsertNextLayer = false;
                 node.IsInsertCurrentLayer = false;
                 node.IsExpanded = false;
+                node.IsSelected = false;
                 node.Outline = outline;
+                node.CanUp = outline.Level == 0 ? false : true;
+                node.CanAddParent = outline.Level == 0 ? false : true;
                 CPDFAction action = outline.GetAction();
                 if (action != null)
                 {
@@ -190,24 +312,44 @@ namespace PDF_Office.ViewModels.BOTA
                         CPDFDestination cPDFDestination = outline.GetDestination(PDFViewer.Document);
                         if (cPDFDestination != null)
                         {
+                            //存储大纲相关属性
                             node.PageIndex = (cPDFDestination.PageIndex + 1).ToString();
+                            node.PositionX = cPDFDestination.Position_X;
+                            node.PositionY = cPDFDestination.Position_Y;
+                            if (cPDFDestination.Zoom <= 0)
+                            {
+                                node.Zoom = 1;
+                            }
+                            else
+                            {
+                                node.Zoom = cPDFDestination.Zoom;
+                            }
                         }
                         else
                         {
                             node.PageIndex = "";
+                            node.PositionX = 0;
+                            node.PositionY = 0;
+                            node.Zoom = 1;
                         }
                     }
                     else
                     {
                         node.PageIndex = "";
+                        node.PositionX = 0;
+                        node.PositionY = 0;
+                        node.Zoom = 1;
                     }
 
                 }
                 else
                 {
                     node.PageIndex = "";
+                    node.PositionX = 0;
+                    node.PositionY = 0;
+                    node.Zoom = 1;
                 }
-               
+
                 if (parent != null)
                 {
                     node.Parent = parent;
@@ -218,6 +360,7 @@ namespace PDF_Office.ViewModels.BOTA
                     if (oldnode != null)
                     {
                         node.IsExpanded = oldnode.IsExpanded;
+                        node.IsSelected = oldnode.IsSelected;
                     }
                 }
                 node.Chlidlist = new ObservableCollection<OutlineNode>();
@@ -228,11 +371,15 @@ namespace PDF_Office.ViewModels.BOTA
                         node.Chlidlist.Add(ConvertCPDFToOutlineNode(item, node, IsMoveData));
                     }
                 }
+                else
+                {
+                    node.CanDown = false;
+                }
             }
             return node;
         }
 
-        public OutlineNode FindOutlineFromDto(ObservableCollection<OutlineNode> list, CPDFOutline outline,bool IsMoveData)
+        public OutlineNode FindOutlineFromDto(ObservableCollection<OutlineNode> list, CPDFOutline outline, bool IsMoveData)
         {
             foreach (OutlineNode item in list)
             {
@@ -286,5 +433,23 @@ namespace PDF_Office.ViewModels.BOTA
             }
             return -1;
         }
+        private int GetOutlinesIndexFormParent(CPDFOutline parentoutline, CPDFOutline outline)
+        {
+            if (parentoutline != null)
+            {
+                if (parentoutline.ChildList.Count > 0)
+                {
+                    for (int i = 0; i < parentoutline.ChildList.Count; i++)
+                    {
+                        if (parentoutline.ChildList[i] == outline)
+                        {
+                            return i + 1;
+                        }
+                    }
+                }
+                return parentoutline.ChildList.Count;
+            }
+            return 0;
+        }
     }
 }

+ 13 - 8
PDF Office/Views/BOTA/OutLineControl.xaml

@@ -49,12 +49,17 @@
                             </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>
@@ -74,7 +79,6 @@
                 VirtualizingPanel.ScrollUnit="Pixel"
                 Drop="OutlineView_Drop"
                 PreviewMouseMove="OutlineView_PreviewMouseMove" 
-                PreviewMouseLeftButtonDown="OutlineView_PreviewMouseLeftButtonDown"
                 PreviewMouseLeftButtonUp="OutlineView_PreviewMouseLeftButtonUp"
                 PreviewMouseDoubleClick="OutlineView_PreviewMouseDoubleClick"
                 ScrollViewer.HorizontalScrollBarVisibility="Disabled">
@@ -85,28 +89,28 @@
                                 <ContextMenu>
                                     <MenuItem Header="添加条目"/>
                                     <MenuItem Header="添加子条目"/>
-                                    <MenuItem Header="添加上一级条目"/>
+                                    <MenuItem Header="添加上一级条目" IsEnabled="{Binding CanAddParent}"/>
                                     
-                                    <MenuItem Header="删除"/>
+                                    <MenuItem x:Name="DeleteMenu" Click="DeleteMenu_Click" Header="删除"/>
 
-                                    <MenuItem Header="重命名"/>
+                                    <MenuItem x:Name="RenameMenu" Click="RenameMenu_Click" Header="重命名"/>
                                     <MenuItem Header="更改目标位置"/>
 
-                                    <MenuItem Header="升级"/>
-                                    <MenuItem 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:PlayViewEdit />
+                                        <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}" VerticalAlignment="Center" TextTrimming="CharacterEllipsis"/>
+                                <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>
 
@@ -125,6 +129,7 @@
                 </TreeView.ItemTemplate>
                 <TreeView.ItemContainerStyle>
                     <Style BasedOn="{StaticResource OutLineItemStyle}" TargetType="TreeViewItem">
+                        <EventSetter Event="PreviewMouseLeftButtonUp" Handler="TreeViewItem_PreviewMouseLeftButtonUp"/>
                     </Style>
                 </TreeView.ItemContainerStyle>
             </TreeView>

+ 90 - 19
PDF Office/Views/BOTA/OutLineControl.xaml.cs

@@ -5,11 +5,13 @@ using PDF_Office.Model.BOTA;
 using PDF_Office.ViewModels.BOTA;
 using System;
 using System.Collections.Generic;
+using System.Collections.ObjectModel;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using System.Windows;
 using System.Windows.Controls;
+using System.Windows.Controls.Primitives;
 using System.Windows.Data;
 using System.Windows.Documents;
 using System.Windows.Input;
@@ -72,6 +74,7 @@ namespace PDF_Office.Views.BOTA
         /// <param name="e"></param>
         private void Grid_DragOver(object sender, DragEventArgs e)
         {
+            (DataContext as OutLineControlViewModel).IsOnDrop = true;
             TreeViewItem sourceitem = e.Data.GetData(typeof(TreeViewItem)) as TreeViewItem;
             if (sourceitem == null)
             {
@@ -157,15 +160,10 @@ namespace PDF_Office.Views.BOTA
                 return;
             }
             ReNameOutlineNode = viewitem;
-            text.Visibility = Visibility.Collapsed;
+            ReNameOutlineNode.IsReName = Visibility.Collapsed;
             e.Handled = true;
         }
 
-        private void OutlineView_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
-        {
-
-        }
-
         private void OutlineView_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
         {
             (DataContext as OutLineControlViewModel).IsInsertHead = false;
@@ -183,13 +181,13 @@ namespace PDF_Office.Views.BOTA
             OutlineNode soureoutlineNode = souredata.DataContext as OutlineNode;
             Point pos = e.GetPosition(OutlineView);
             HitTestResult result = VisualTreeHelper.HitTest(OutlineView, pos);
-            if (result==null)
+            if (result == null)
             {
                 HiddenaAllLine();
                 return;
             }
             TreeViewItem targetitem = CommonHelper.FindVisualParent<TreeViewItem>(result.VisualHit);
-            if (targetitem==null)
+            if (targetitem == null)
             {
                 HiddenaAllLine();
                 return;
@@ -206,8 +204,12 @@ namespace PDF_Office.Views.BOTA
             (DataContext as OutLineControlViewModel).Updata(true);
         }
 
+        /// <summary>
+        /// 清理线条显示,以及相关缓存对象
+        /// </summary>
         private void HiddenaAllLine()
         {
+            (DataContext as OutLineControlViewModel).IsOnDrop = false;
             (DataContext as OutLineControlViewModel).IsInsertHead = false;
             if (Treeviewitem != null)
             {
@@ -266,21 +268,90 @@ namespace PDF_Office.Views.BOTA
 
         private void ToolTip_Opened(object sender, RoutedEventArgs e)
         {
-            var x= CommonHelper.FindVisualChild<PlayViewEdit>(sender as ToolTip);
-
-            DrawingContext drawDc= x.OpenDraw();
-            WriteableBitmap imageData= (DataContext as OutLineControlViewModel).LoadPreview();
-            drawDc.DrawImage(imageData, new Rect(0, 0, imageData.Width, imageData.Height));
-            x.Width = imageData.Width;
-            x.Height = imageData.Height;
-            x.CloseDraw();
+            CustomImageControl imageControl = CommonHelper.FindVisualChild<CustomImageControl>(sender as ToolTip);
+           
+            OutlineNode outline = imageControl.DataContext as OutlineNode;
+            if (outline == null || string.IsNullOrEmpty(outline.PageIndex))
+            {
+                return;
+            }
+            //开始绘制
+            DrawingContext drawDc = imageControl.OpenDraw();
+            WriteableBitmap imageData = (DataContext as OutLineControlViewModel).LoadPreview(outline);
+            if (imageData == null)
+            {
+                imageControl.CloseDraw();
+                return;
+            }
+            drawDc.DrawImage(imageData, new Rect(0, 0, imageControl.Width, imageControl.Height));
+            imageControl.CloseDraw();
         }
 
         private void ToolTip_Closed(object sender, RoutedEventArgs e)
         {
-            var x = CommonHelper.FindVisualChild<PlayViewEdit>(sender as ToolTip);
-            x.OpenDraw();
-            x.CloseDraw();
+            CustomImageControl imageControl = CommonHelper.FindVisualChild<CustomImageControl>(sender as ToolTip);
+            //清空绘制上下文数据
+            imageControl.OpenDraw();
+            imageControl.CloseDraw();
+        }
+
+        private void TreeViewItem_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
+        {
+            if (e.ClickCount == 1)
+            {
+                TreeViewItem content = sender as TreeViewItem;
+                if (content == null)
+                    return;
+                Point p = e.GetPosition(OutlineView);
+                HitTestResult result = VisualTreeHelper.HitTest(OutlineView, p);
+                if (result != null)
+                {
+                    //点击部位为箭头时,不跳转
+                    ToggleButton button = CommonHelper.FindVisualParent<ToggleButton>(result.VisualHit);
+                    if (button != null)
+                        return;
+                    Button btn = CommonHelper.FindVisualParent<Button>(result.VisualHit);
+                    if (btn != null)
+                        return;
+                    (DataContext as OutLineControlViewModel).GoToPage(content);
+                }
+            }
+        }
+
+        private void MenuCollapseAll_Click(object sender, RoutedEventArgs e)
+        {
+            (DataContext as OutLineControlViewModel).CollapseAll(OutlineView.ItemsSource as ObservableCollection<OutlineNode>);
+        }
+
+        private void MenuExpandAll_Click(object sender, RoutedEventArgs e)
+        {
+            (DataContext as OutLineControlViewModel).ExpandAll(OutlineView.ItemsSource as ObservableCollection<OutlineNode>);
+        }
+
+        private void MenuDeleteAll_Click(object sender, RoutedEventArgs e)
+        {
+            (DataContext as OutLineControlViewModel).DeleteAll();
+        }
+
+        private void DowngradeMenu_Click(object sender, RoutedEventArgs e)
+        {
+            (DataContext as OutLineControlViewModel).Downgrade((sender as MenuItem).DataContext as OutlineNode);
+        }
+
+        private void UpgradeMenu_Click(object sender, RoutedEventArgs e)
+        {
+            (DataContext as OutLineControlViewModel).Upgrade((sender as MenuItem).DataContext as OutlineNode);
+        }
+
+        private void DeleteMenu_Click(object sender, RoutedEventArgs e)
+        {
+            (DataContext as OutLineControlViewModel).RemoveOutline((sender as MenuItem).DataContext as OutlineNode);
+        }
+
+        private void RenameMenu_Click(object sender, RoutedEventArgs e)
+        {
+            ReNameOutlineNode = (sender as MenuItem).DataContext as OutlineNode;
+            ReNameOutlineNode.IsReName = Visibility.Collapsed;
         }
     }
 }