Bladeren bron

编辑-优化UI显示速度

OYXH\oyxh 1 jaar geleden
bovenliggende
commit
654d142f39

+ 3 - 1
PDF Office/CustomControl/CompositeControl/CustomComboControl.xaml

@@ -52,7 +52,9 @@
                         BorderBrush="#FFE2E3E6"
                         BorderThickness="1"
                         ItemTemplate="{StaticResource numberData}"
-                        MaxDropDownHeight="200">
+                        MaxDropDownHeight="200"
+                        VirtualizingStackPanel.IsVirtualizing="True"
+                        VirtualizingStackPanel.VirtualizationMode="Standard">
                         <ComboBox.ItemsPanel>
                             <ItemsPanelTemplate>
                                 <VirtualizingStackPanel />

+ 95 - 109
PDF Office/ViewModels/Tools/TextEditToolContentViewModel.cs

@@ -28,30 +28,39 @@ using System.Windows.Media.Imaging;
 using PDFReader_WPF.Helper;
 using PDF_Master.Properties;
 using PDF_Master.Model.AnnotPanel;
+using System.Diagnostics;
 
 namespace PDF_Master.ViewModels.Tools
 {
-    public class TextEditToolContentViewModel: BindableBase, INavigationAware
+    public class TextEditToolContentViewModel : BindableBase, INavigationAware
     {
         #region 属性与变量
+
         public ViewContentViewModel viewContentViewModel;
         private CPDFViewer PDFViewer;
         private IEventAggregator events;
         private IRegionManager regions;
+
         /// <summary>
         /// 用于区分事件的唯一码
         /// </summary>
         private string unicode;
+
         private Dictionary<string, string> btnToProperty = new Dictionary<string, string>();
 
         private bool _isTextEdit = false;
+
         public bool IsTextEdit
         {
             get { return _isTextEdit; }
-            set { SetProperty(ref _isTextEdit, value);
+            set
+            {
+                SetProperty(ref _isTextEdit, value);
             }
         }
+
         private bool _isImgEdit = false;
+
         public bool IsImgEdit
         {
             get { return _isImgEdit; }
@@ -61,7 +70,8 @@ namespace PDF_Master.ViewModels.Tools
             }
         }
 
-        private bool _flg=false;
+        private bool _flg = false;
+
         public bool flg
         {
             get { return _flg; }
@@ -72,6 +82,7 @@ namespace PDF_Master.ViewModels.Tools
         /// 替换图片指令
         /// </summary>
         private bool _ReplaceImgflg = false;
+
         public bool ReplaceImgflg
         {
             get { return _ReplaceImgflg; }
@@ -82,32 +93,39 @@ namespace PDF_Master.ViewModels.Tools
         /// 完成裁剪图片指令
         /// </summary>
         private bool _CropImgflg = false;
+
         public bool CropImgflg
         {
             get { return _CropImgflg; }
             set { SetProperty(ref _CropImgflg, value); }
         }
+
         /// <summary>
         /// 刷新预览图片指令
         /// </summary>
         private bool _REImgflg = false;
+
         public bool REImgflg
         {
             get { return _REImgflg; }
             set { SetProperty(ref _REImgflg, value); }
         }
-        #endregion
+
+        #endregion 属性与变量
 
         #region Command
+
         // 添加文本、图像
         public DelegateCommand<object> AddContentCommand { get; set; }
+
         public DelegateCommand AddTextCommand { get; set; }
         public DelegateCommand AddImgCommand { get; set; }
         public DelegateCommand EditTextModeCommand { get; set; }
 
-        #endregion
+        #endregion Command
 
         #region 初始化
+
         public TextEditToolContentViewModel(IRegionManager regionManager, IEventAggregator eventAggregator)
         {
             events = eventAggregator;
@@ -116,6 +134,7 @@ namespace PDF_Master.ViewModels.Tools
             InitCommand();
             InitBtnToProperty();
         }
+
         private void InitCommand()
         {
             AddContentCommand = new DelegateCommand<object>(AddContent);
@@ -132,7 +151,8 @@ namespace PDF_Master.ViewModels.Tools
             btnToProperty.Add("PropertyPanelContentEdit", "PropertyPanelContentEdit");
         }
 
-        #endregion
+        #endregion 初始化
+
         #region 右键菜单
 
         //点击空白处时
@@ -155,7 +175,7 @@ namespace PDF_Master.ViewModels.Tools
         {
             var popMenu = App.Current.FindResource("SelectTextMenu") as ContextMenu;
             CustomPopMenu customMenu = new CustomPopMenu(popMenu, sender);
-         
+
             //复制
             customMenu.SetMenuBinding(0, ApplicationCommands.Copy);
             //剪切
@@ -169,7 +189,7 @@ namespace PDF_Master.ViewModels.Tools
 
             return popMenu;
         }
-       
+
         //选中文字内容
         private ContextMenu SelectTextContent(object sender)
         {
@@ -209,10 +229,11 @@ namespace PDF_Master.ViewModels.Tools
             ////删除
             //customMenu.SetMenuBinding(4, ApplicationCommands.Delete);
 
-
             return popMenu;
         }
-        #endregion
+
+        #endregion 右键菜单
+
         #region 图片右键菜单
 
         //选中图像时
@@ -252,6 +273,7 @@ namespace PDF_Master.ViewModels.Tools
             customMenu.SetMenuBinding(2, new DelegateCommand(RestoreCropImg));
             return popMenu;
         }
+
         //多选图片右键
         private ContextMenu SelectMoreImage(object sender)
         {
@@ -268,11 +290,13 @@ namespace PDF_Master.ViewModels.Tools
             //导出
             customMenu.SetMenuBinding(4, new DelegateCommand(ExportImg));
 
-
             return popMenu;
         }
-        #endregion
+
+        #endregion 图片右键菜单
+
         #region 快捷键
+
         private void ShortCut_KeyDown(object sender, KeyEventArgs e)
         {
             try
@@ -284,35 +308,33 @@ namespace PDF_Master.ViewModels.Tools
                         //缩小esc的操作范围
                         if (PDFViewer.ToolManager != null && PDFViewer.GetPDFEditCreateType() == ComPDFKit.PDFPage.CPDFEditType.EditText)
                         {
-                            if(PDFViewer.GetPDFEditSelectionCount(ComPDFKit.PDFPage.CPDFEditType.EditText) ==0)
-                            {
-                              PDFViewer.RemovePDFEditEmptyText(); 
-                            //只有在有画框的时候才进行
-                            if (PDFViewer.MouseMode == MouseModes.PDFEdit&& PDFViewer.ToolManager.HasTool == true)
+                            if (PDFViewer.GetPDFEditSelectionCount(ComPDFKit.PDFPage.CPDFEditType.EditText) == 0)
                             {
-                                PDFViewer.RemoveTool(false);
-                            }
-                            else if (IsTextEdit == true || IsImgEdit == true)
-                            {
-                                IsImgEdit = false;
-                                IsTextEdit = false;
-                                PDFViewer.SetPDFEditCreateType(ComPDFKit.PDFPage.CPDFEditType.None);
+                                PDFViewer.RemovePDFEditEmptyText();
+                                //只有在有画框的时候才进行
+                                if (PDFViewer.MouseMode == MouseModes.PDFEdit && PDFViewer.ToolManager.HasTool == true)
+                                {
+                                    PDFViewer.RemoveTool(false);
+                                }
+                                else if (IsTextEdit == true || IsImgEdit == true)
+                                {
+                                    IsImgEdit = false;
+                                    IsTextEdit = false;
+                                    PDFViewer.SetPDFEditCreateType(ComPDFKit.PDFPage.CPDFEditType.None);
 
-                                //文本和图像都框选
-                                PDFViewer.SetPDFEditType(ComPDFKit.PDFPage.CPDFEditType.EditText | ComPDFKit.PDFPage.CPDFEditType.EditImage);
-                                PDFViewer.SetMouseMode(MouseModes.PDFEdit);                           
-                                PDFViewer.ReloadDocument();
-                                ShowPropertyPanel(false);
-                            }
+                                    //文本和图像都框选
+                                    PDFViewer.SetPDFEditType(ComPDFKit.PDFPage.CPDFEditType.EditText | ComPDFKit.PDFPage.CPDFEditType.EditImage);
+                                    PDFViewer.SetMouseMode(MouseModes.PDFEdit);
+                                    PDFViewer.ReloadDocument();
+                                    ShowPropertyPanel(false);
+                                }
                             }
                             {
                                 PDFViewer.ClearSelectPDFEdit();
                                 PDFViewer.RemovePDFEditEmptyText();
                                 PDFViewer.ReloadDocument();
                             }
-                          
                         }
-
                         else if (PDFViewer.ToolManager != null && PDFViewer.GetPDFEditCreateType() == ComPDFKit.PDFPage.CPDFEditType.EditImage)
                         {
                             if (PDFViewer.GetPDFEditSelectionCount(ComPDFKit.PDFPage.CPDFEditType.EditImage) == 0)
@@ -341,32 +363,21 @@ namespace PDF_Master.ViewModels.Tools
                                 PDFViewer.ReloadDocument();
                             }
                         }
-                        
                         else if (PDFViewer.ToolManager != null)
                         {
                             PDFViewer.ClearSelectPDFEdit();
                             AddToPropertyPanel("PropertyPanelContentEdit", null);
                             PDFViewer.ReloadDocument();
-
                         }
-
-
-
                     }
                 }
-
-
-
             }
             catch
             {
-
             }
-           
-          
-
         }
-        #endregion
+
+        #endregion 快捷键
 
         //模式选择进入
         public void AddContent(object obj)
@@ -378,21 +389,21 @@ namespace PDF_Master.ViewModels.Tools
                 IsImgEdit = false;
                 IsTextEdit = false;
                 PDFViewer.SetPDFEditType(ComPDFKit.PDFPage.CPDFEditType.None);
-                PDFViewer.ReloadDocument();              
+                PDFViewer.ReloadDocument();
                 App.mainWindowViewModel.OpenLogin();
                 return;
             }
             var btn = obj as CustomIconToggleBtn;
             EnterEditMode((bool)btn.IsChecked, btn.Tag.ToString());
         }
+
         //编辑按钮逻辑,暂时保留
         private void EditTextMode()
         {
-
         }
-        
+
         //对应模式的逻辑
-        private void EnterEditMode(bool isCheckMode,string modeType)
+        private void EnterEditMode(bool isCheckMode, string modeType)
         {
             if (isCheckMode)
             {
@@ -435,7 +446,6 @@ namespace PDF_Master.ViewModels.Tools
                     PDFViewer.ReloadDocument();
                     AddToPropertyPanel("PropertyPanelContentEdit", null);
                     ShowPropertyPanel(true);
-                    
                 }
             }
             else
@@ -449,7 +459,6 @@ namespace PDF_Master.ViewModels.Tools
                 PDFViewer.SetMouseMode(MouseModes.PDFEdit);
                 PDFViewer.ReloadDocument();
                 ShowPropertyPanel(false);
-
             }
         }
 
@@ -464,12 +473,12 @@ namespace PDF_Master.ViewModels.Tools
         {
             EnterEditMode(true, "Image");
         }
+
         //进入裁剪模式
         private void CropMode()
         {
             if (TextEditEvent != null)
             {
-              
                 TextEditEvent.ClipImage = true;
                 TextEditEvent.UpdatePDFEditByEventArgs();
                 flg = true;
@@ -496,16 +505,14 @@ namespace PDF_Master.ViewModels.Tools
                 TextEditEvent.RestoreClip();
                 events.GetEvent<PageEditNotifyEvent>().Publish(new PageEditNotifyEventArgs(unicode));
             }
-            
         }
 
         //完成裁剪
         private void CropImg()
         {
-
             CropImgflg = true;
-          
         }
+
         //导出图片
         private void ExportImg()
         {
@@ -534,16 +541,19 @@ namespace PDF_Master.ViewModels.Tools
                 CommonHelper.ShowFileBrowser(strFilePath);
             }
         }
-            //替换图片
-            private void ReplaceImg()
+
+        //替换图片
+        private void ReplaceImg()
         {
             ReplaceImgflg = true;
         }
 
-      
         //选中的图像
         private System.Windows.Media.Imaging.BitmapSource _currentImg;
-        public System.Windows.Media.Imaging.BitmapSource CurrentImg { get { return _currentImg; } set { SetProperty(ref _currentImg, value); } }
+
+        public System.Windows.Media.Imaging.BitmapSource CurrentImg
+        { get { return _currentImg; } set { SetProperty(ref _currentImg, value); } }
+
         private void GetImagePreView()
         {
             try
@@ -568,21 +578,17 @@ namespace PDF_Master.ViewModels.Tools
                         System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
                         CurrentImg = bitmapSource;
                     }
-
                 }
             }
             catch
             {
-
             }
-
         }
-        #endregion
-
 
+        #endregion Command功能
 
         //传参数给属性面板
-        private void AddToPropertyPanel(string type,  List<PDFEditEvent> e)
+        private void AddToPropertyPanel(string type, List<PDFEditEvent> e)
         {
             if (btnToProperty.ContainsKey(type))
             {
@@ -595,11 +601,11 @@ namespace PDF_Master.ViewModels.Tools
                     regions.RequestNavigate(RegionNames.PropertyRegionName, btnToProperty[type], parameters);
                 }));
 
-                if(e!=null)
+                if (e != null)
                 {
                     ShowPropertyPanel(true);
                 }
-                else if(e==null&&IsImgEdit==false&&IsTextEdit==false)
+                else if (e == null && IsImgEdit == false && IsTextEdit == false)
                 {
                     ShowPropertyPanel(false);
                 }
@@ -629,13 +635,12 @@ namespace PDF_Master.ViewModels.Tools
                 }
                 else
                 {
-
                     PDFViewer.SetPDFEditType(ComPDFKit.PDFPage.CPDFEditType.None);
                     PDFViewer.ReloadDocument();
-
                 }
             }
         }
+
         public void OnNavigatedTo(NavigationContext navigationContext)
         {
             navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
@@ -652,7 +657,6 @@ namespace PDF_Master.ViewModels.Tools
                 PDFViewer.PDFEditCommandHandler -= PDFViewer_PDFEditCommandHandler;
                 PDFViewer.PDFEditCommandHandler += PDFViewer_PDFEditCommandHandler;
 
-
                 //图片添加
                 PDFViewer.CustomNotifyHandler -= PDFViewer_CustomNotifyHandler;
                 PDFViewer.CustomNotifyHandler += PDFViewer_CustomNotifyHandler;
@@ -669,14 +673,15 @@ namespace PDF_Master.ViewModels.Tools
         private void PDFViewer_PDFEditHandler(object sender, List<PDFEditSelectionData> e)
         {
             PDFViewer.ClearSelectPDFEdit();
-            PDFViewer.SelectPDFEdit(e,true);
+            PDFViewer.SelectPDFEdit(e, true);
         }
 
         protected PDFEditEvent TextEditEvent;
+
         //左键激活逻辑
         private void PDFViewer_PDFEditActiveHandler(object sender, List<PDFEditEvent> e)
         {
-            PDFViewer.ToolManager.IgnoreMoveDistance =5;
+            PDFViewer.ToolManager.IgnoreMoveDistance = 5;
             //判断是否已退出登录,限制编辑操作
             if (!App.IsLogin)
             {
@@ -689,12 +694,11 @@ namespace PDF_Master.ViewModels.Tools
             }
             if (e != null && e.Count > 0)
             {
-                TextEditEvent=e[0];
+                TextEditEvent = e[0];
                 bool isText = false;
                 bool isImg = false;
                 foreach (var item in e)
                 {
-
                     if (item.EditType == ComPDFKit.PDFPage.CPDFEditType.EditImage)
                     {
                         isImg = true;
@@ -705,26 +709,21 @@ namespace PDF_Master.ViewModels.Tools
                         isText = true;
                     }
                 }
-               
-              
 
                 if (isText == true && isImg == false)
                 {
                     AddToPropertyPanel("Text", e);
-                  
                 }
                 if (isText == false && isImg == true)
                 {
                     AddToPropertyPanel("Image", e);
-                 
                 }
                 if (isText == true && isImg == true)
                 {
                     AddToPropertyPanel("TextAndImage", e);
-                   
                 }
             }
-
+            ///未事先设置 if里面的内容,单击添加文本会失败
             //else if(IsTextEdit==true)
             //{
             //    //单击添加文本
@@ -735,12 +734,11 @@ namespace PDF_Master.ViewModels.Tools
             //}
             else
             {
-
+                Trace.WriteLine("PropertyPanelContentEdit");
                 AddToPropertyPanel("PropertyPanelContentEdit", null);
             }
 
             events.GetEvent<PageEditNotifyEvent>().Publish(new PageEditNotifyEventArgs(unicode));
-
         }
 
         //右键点击逻辑
@@ -756,34 +754,28 @@ namespace PDF_Master.ViewModels.Tools
                     if (e.EditType == ComPDFKit.PDFPage.CPDFEditType.None)//点击空白区域
                     {
                         e.PopupMenu = EmptyStateMenu(sender);
-
                     }
                     else if (e.EditType == ComPDFKit.PDFPage.CPDFEditType.EditText)
                     {
-
-                         
                         //文字编辑
                         if (e.PressOnBorder == true)
                         {
                             e.PopupMenu = SelectTextBorder(sender);
                         }
-
-                         else if(e.PressOnSelectedText == true)
+                        else if (e.PressOnSelectedText == true)
                         {
                             e.PopupMenu = SelectTextContent(sender);
                         }
-
-                        else if(e.SelectText=="")
+                        else if (e.SelectText == "")
                         {
-                            e.PopupMenu= EditTextContent(sender);
+                            e.PopupMenu = EditTextContent(sender);
                         }
                         else
                         {
                             e.PopupMenu = SelectTextContent(sender);
                         }
-
                     }
-                   else if (e.EditType == ComPDFKit.PDFPage.CPDFEditType.EditImage)
+                    else if (e.EditType == ComPDFKit.PDFPage.CPDFEditType.EditImage)
                     {
                         if (e.IsClipState == true)
                         {
@@ -793,15 +785,13 @@ namespace PDF_Master.ViewModels.Tools
                         {
                             e.PopupMenu = SelectImgPDFEdit(sender);
                         }
-
                     }
-                  
-                        break;
+
+                    break;
 
                 default:
                     e.DoCommand();
                     break;
-
             }
             if (e.PopupMenu != null)
             {
@@ -810,7 +800,6 @@ namespace PDF_Master.ViewModels.Tools
             flg = e.IsClipState;
         }
 
-
         //图片添加逻辑
         private void PDFViewer_CustomNotifyHandler(object sender, CustomNotityData e)
         {
@@ -818,15 +807,15 @@ namespace PDF_Master.ViewModels.Tools
             if (e.NotifyType == CustomNotifyType.PDFEditImageCreate)
             {
                 OpenFileDialog openFileDialog = new OpenFileDialog();
-                    openFileDialog.Filter = "Image Files(*.jpg;*.jpeg;*.png;*.bmp)|*.jpg;*.jpeg;*.png;*.bmp;";
-                    if (openFileDialog.ShowDialog() == true)
-                    {                 
-                    PDFViewer.AddPDFEditImage(CompressImage(openFileDialog.FileName, 800), 500,500);
+                openFileDialog.Filter = "Image Files(*.jpg;*.jpeg;*.png;*.bmp)|*.jpg;*.jpeg;*.png;*.bmp;";
+                if (openFileDialog.ShowDialog() == true)
+                {
+                    PDFViewer.AddPDFEditImage(CompressImage(openFileDialog.FileName, 800), 500, 500);
                     events.GetEvent<PageEditNotifyEvent>().Publish(new PageEditNotifyEventArgs(unicode));
                 }
-                }
+            }
             //图片调整大小
-            else if(e.NotifyType == CustomNotifyType.PDFEditImageResize)
+            else if (e.NotifyType == CustomNotifyType.PDFEditImageResize)
             {
                 REImgflg = true;
                 events.GetEvent<PageEditNotifyEvent>().Publish(new PageEditNotifyEventArgs(unicode));
@@ -888,7 +877,6 @@ namespace PDF_Master.ViewModels.Tools
             }
         }
 
-
         /// <summary>
         ///  根据图片数据判断图片类型
         /// </summary>
@@ -912,7 +900,6 @@ namespace PDF_Master.ViewModels.Tools
                 }
                 catch
                 {
-
                     extension = FileExtension.VALIDFILE;
                 }
                 return extension;
@@ -935,18 +922,17 @@ namespace PDF_Master.ViewModels.Tools
         {
             return true;
         }
-       
+
         public void OnNavigatedFrom(NavigationContext navigationContext)
         {
             IsImgEdit = false;
             IsTextEdit = false;
             PDFViewer.PDFEditActiveHandler -= PDFViewer_PDFEditActiveHandler;
             PDFViewer.PDFEditCommandHandler -= PDFViewer_PDFEditCommandHandler;
-             PDFViewer.CustomNotifyHandler -= PDFViewer_CustomNotifyHandler;
+            PDFViewer.CustomNotifyHandler -= PDFViewer_CustomNotifyHandler;
             PDFViewer.PDFEditHandler -= PDFViewer_PDFEditHandler;
             KeyEventsHelper.KeyDown -= ShortCut_KeyDown;
             ShowPropertyPanel(false);
         }
-
     }
-}
+}