Browse Source

填充与签名

liyijie 2 years ago
parent
commit
e1617eba55

+ 348 - 178
PDF Office/ViewModels/FillAndSign/FillAndSignContentViewModel.cs

@@ -21,6 +21,12 @@ using ComPDFKit.PDFDocument.Action;
 using ComPDFKit.PDFDocument;
 using System.Diagnostics;
 using ComPDFKit.PDFAnnotation;
+using PDF_Office.ViewModels.BOTA;
+using PDF_Office.Views.BOTA;
+using System.Windows.Forms;
+using Control = System.Windows.Controls.Control;
+using Microsoft.Office.Interop.Word;
+using Point = System.Windows.Point;
 
 namespace PDF_Office.ViewModels.FillAndSign
 {
@@ -30,11 +36,18 @@ namespace PDF_Office.ViewModels.FillAndSign
         private CPDFViewer PDFViewer;
         private AnnotPropertyPanel propertyPanel = new AnnotPropertyPanel();
         private ViewContentViewModel viewContentViewModel;
-        private bool isRightMenuAddAnnot = false;
+        private bool isRightMenuAddAnnot = false;
+        private List<List<Point>> ShapePoints = new List<List<Point>>();
+        private string Shape = "HookShape";
+                   
         private IRegionManager regions { get; set; }
         private Dictionary<string, AnnotArgsType> ToolExpandDict = new Dictionary<string, AnnotArgsType>();
-        #endregion
 
+        public Brush SelectColor=new SolidColorBrush(Colors.GreenYellow);
+        public double FillOpacity = 1;
+        public double LineWidth = 1;
+        #endregion
+
         #region Command
         public DelegateCommand<RoutedEventArgs> CheckCommand { get; set; }
 
@@ -57,77 +70,100 @@ namespace PDF_Office.ViewModels.FillAndSign
         {
             var control = e.OriginalSource as Control;
 
-            NavigateToProperty(control.Name);
+            //NavigateToProperty(control.Name);
             //不创建注释,属于注释模板
-            //bool isTemplateAnnot = false;
-            //bool isSnapshotEdit = false;
-            //AnnotHandlerEventArgs annotArgs = null;
-
-           
-            //    var tag = control.Name;
-            //    if (control.Name == "RbtnSign") {  FindAnnotTypeKey("Signature", ref annotArgs); isTemplateAnnot = true; }
-            //    if (control.Name == "RbtnText") { FindAnnotTypeKey("Freetext", ref annotArgs);  }
-            //if (control.Name == "RbtnDate") { FindAnnotTypeKey("Freetext", ref annotArgs); } 
-
-            //    if (tag == "SnapshotEdit")
-            //    {
-            //        isSnapshotEdit = true;
-            //    }
-            //    else if (tag == "Signature" || tag == "Stamp")
-            //    {
-            //        isTemplateAnnot = true;
-            //    }
-
-            //    if (annotArgs != null)
-            //    {
-            //        annotArgs.Author = Settings.Default.AppProperties.Description.Author;
-            //        PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
-            //        PDFViewer.SetToolParam(annotArgs);
-            //        isRightMenuAddAnnot = false;
-            //    }
-            
-
-            ////当不是注释模板,且无创建注释时,属性面板显示为空内容
-            //if (isTemplateAnnot == false && annotArgs == null)
-            //{
-            //    PDFViewer.SetMouseMode(MouseModes.PanTool);
-            //    viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
-            //}
-            //else
-            //{
-            //    if (isSnapshotEdit == true)
-            //    {
-            //        ShowPropertyPanel(false);
-            //        isSnapshotEdit = false;
-            //    }
-            //    else
-            //    {
-            //        ShowPropertyPanel(true);
-            //    }
-            //}
-            
+            bool isTemplateAnnot = false;
+            bool isSnapshotEdit = false;
+            AnnotHandlerEventArgs annotArgs = null;
+
+
+            var tag = control.Name;
+            FindAnnotTypeKey(control.Name, ref annotArgs);
+            if (control.Name == "RbtnSign") { isTemplateAnnot = true; }
+
+
+            if (tag == "SnapshotEdit")
+            {
+                isSnapshotEdit = true;
+            }
+            else if (tag == "Signature" || tag == "Stamp")
+            {
+                isTemplateAnnot = true;
+            }
+
+            if (annotArgs != null)
+            {
+                annotArgs.Author = Settings.Default.AppProperties.Description.Author;
+                PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
+                PDFViewer.SetToolParam(annotArgs);
+                isRightMenuAddAnnot = false;
+            }
+
+
+            //当不是注释模板,且无创建注释时,属性面板显示为空内容
+            if (isTemplateAnnot == false && annotArgs == null)
+            {
+                PDFViewer.SetMouseMode(MouseModes.PanTool);
+                viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
+            }
+            else
+            {
+                if (isSnapshotEdit == true)
+                {
+                    ShowPropertyPanel(false);
+                    isSnapshotEdit = false;
+                }
+                else
+                {
+                    ShowPropertyPanel(true);
+                }
+            }
+
         }
-
         //注释工具
         private void FindAnnotTypeKey(string tag, ref AnnotHandlerEventArgs annotArgs, bool isRightMenuAdd = false)
         {
             switch (tag)
-            {
-                
-
+            {
+
+                case "RbtnDate":
+                case "RbtnText"://文本
+                    annotArgs = GetFreetext();
+                    break;
                 case "Freetext"://文本
                     annotArgs = GetFreetext();
                     break;
-
-                case "Stamp"://图章
-                    annotArgs = GetStamp();
-                    break;
-
-                case "Signature"://签名
+                case "RbtnSign"://签名
                     annotArgs = GetSignature();
                     PDFViewer.SetMouseMode(MouseModes.PanTool);//清空其他注释
+                    break;
+                case "RbtnTick"://勾
+                    Shape = "HookShape";
+                    ShapePoints =new List<List<Point>> { new List<Point> { new Point(0.599976,7.0286), new Point(5.57775,11.8), new Point(13.4,1.40002)} };
+                    annotArgs = GetStamp();
+                    break;
+                case "RbtnFork"://叉
+                    Shape = "ForkShape";
+                    ShapePoints = new List<List<Point>> { new List<Point> { new Point(3.19995, 3.20001), new Point(12.8, 12.8) } ,new List<Point> { new Point(12.8, 3.20001), new Point(3.20005, 12.8) }};
+                    annotArgs = GetStamp();
+                    break;
+                case "RbtnRectangle"://矩形
+                    Shape = "RectShape";
+                    ShapePoints = new List<List<Point>> { new List<Point> { new Point(0, 5), new Point(28, 5),new Point(28,27),new Point(0,27) , new Point(0, 5) } };
+                    annotArgs = GetStamp();
+                    break;
+                case "RbtnLine"://下划线
+                    Shape = "LineShape";
+                    ShapePoints = new List<List<Point>> { new List<Point> { new Point(12, 10), new Point(36, 10) } };
+                    annotArgs = GetStamp();
+                    break;
+                case "RbtnPoint":
+                    Shape = "DotShape";
+                    ShapePoints = new List<List<Point>> { new List<Point> { new Point(0, 0), new Point(2, 2) }, new List<Point> { new Point(2, 0), new Point(0,2 ) } };
+                    annotArgs = GetStamp();
+                    break;
+                default://图章
                     break;
-
             }
         }
         /// <summary>
@@ -147,21 +183,79 @@ namespace PDF_Office.ViewModels.FillAndSign
         /// <returns></returns>
         private AnnotHandlerEventArgs GetStamp()
         {
-            StampAnnotArgs stampAnnotArgs = new StampAnnotArgs();
-            stampAnnotArgs.Opacity = 1;
-            stampAnnotArgs.StampText = "APPROVED";
-            stampAnnotArgs.Type = StampType.STANDARD_STAMP;
+            StampAnnotArgs stampAnnotArgs = new StampAnnotArgs();
+            stampAnnotArgs.SetInkData(ShapePoints, LineWidth, (SelectColor as SolidColorBrush).Color);
+            //PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
+            //PDFViewer.SetToolParam(stampArgs);
+            //StampAnnotArgs stampAnnotArgs = new StampAnnotArgs();
+            //stampAnnotArgs.Opacity = 1;
+            //stampAnnotArgs.StampText = "APPROVED";
+            //stampAnnotArgs.Type = StampType.STANDARD_STAMP;
+           // stampAnnotArgs.Type = StampType.STANDARD_STAMP;
             Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
             annotAttribsList[AnnotAttrib.Transparency] = stampAnnotArgs.Opacity;
-
+            DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotStamp);
             List<AnnotHandlerEventArgs> stampAnnotArgsList = new List<AnnotHandlerEventArgs>();
             if (stampAnnotArgs != null)
                 stampAnnotArgsList.Add(stampAnnotArgs);
 
-            AddToPropertyPanel("StampAnnotProperty", null, stampAnnotArgsList, annotAttribsList);
+            AddToPropertyPanel("ShapFillProperty", "", stampAnnotArgsList, annotAttribsList);
             return stampAnnotArgs;
         }
 
+        public void  SetStamp()
+        {
+            StampAnnotArgs stampAnnotArgs = new StampAnnotArgs();
+            stampAnnotArgs.SetInkData(ShapePoints, LineWidth, (SelectColor as SolidColorBrush).Color);
+            //PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
+            //PDFViewer.SetToolParam(stampArgs);
+            //StampAnnotArgs stampAnnotArgs = new StampAnnotArgs();
+            //stampAnnotArgs.Opacity = 1;
+            //stampAnnotArgs.StampText = "APPROVED";
+            //stampAnnotArgs.Type = StampType.STANDARD_STAMP;
+            stampAnnotArgs.Opacity = FillOpacity;
+            Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
+            annotAttribsList[AnnotAttrib.Transparency] = stampAnnotArgs.Opacity;
+            DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotStamp);
+            List<AnnotHandlerEventArgs> stampAnnotArgsList = new List<AnnotHandlerEventArgs>();
+            if (stampAnnotArgs != null)
+                stampAnnotArgsList.Add(stampAnnotArgs);
+
+            AddToPropertyPanel("ShapFillProperty", "", stampAnnotArgsList, annotAttribsList);
+            bool isTemplateAnnot = false;
+            bool isSnapshotEdit = false;
+            AnnotHandlerEventArgs annotArgs = stampAnnotArgs;
+
+
+            if (annotArgs != null)
+            {
+                annotArgs.Author = Settings.Default.AppProperties.Description.Author;
+                PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
+                PDFViewer.SetToolParam(annotArgs);
+                isRightMenuAddAnnot = false;
+            }
+
+
+            //当不是注释模板,且无创建注释时,属性面板显示为空内容
+            if (isTemplateAnnot == false && annotArgs == null)
+            {
+                PDFViewer.SetMouseMode(MouseModes.PanTool);
+                viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
+            }
+            else
+            {
+                if (isSnapshotEdit == true)
+                {
+                    ShowPropertyPanel(false);
+                    isSnapshotEdit = false;
+                }
+                else
+                {
+                    ShowPropertyPanel(true);
+                }
+            } 
+        }
+
         /// <summary>
         /// 文本
         /// </summary>
@@ -246,7 +340,7 @@ namespace PDF_Office.ViewModels.FillAndSign
         /// <param name="toolTag">导航到同一个注释xaml时,需要区分某个注释;比如高亮、删除线、下划线</param>
         /// <param name="annot">注释</param>
         /// <param name="annotAttribsList">更改注释属性的键值对,更改值后会自动记录undoRedo容器里</param>
-        private void AddToPropertyPanel(string viewContent, string toolTag = null, List<AnnotHandlerEventArgs> annots = null, Dictionary<AnnotAttrib, object> annotAttribsList = null, AnnotAttribEvent annotAttribEvent = null)
+        private void AddToPropertyPanel(string viewContent, string toolTag = null, List<AnnotHandlerEventArgs> annots = null, Dictionary<AnnotAttrib, object> annotAttribsList = null, AnnotAttribEvent annotAttribEvent = null,bool isUpData=false)
         {
 
             if (annots != null)
@@ -282,18 +376,24 @@ namespace PDF_Office.ViewModels.FillAndSign
                     propertyPanel.AnnotEvent = annotAttribEvent;
                 }
             }
-
+            
             if (string.IsNullOrEmpty(viewContent) == false)
             {
+                if (isUpData) { return; }
+                if (viewContent == "ShapFillProperty") { NavigateToProperty(viewContent, propertyPanel); return; }
                 viewContentViewModel.SelectedPrpoertyPanel(viewContent, propertyPanel);
             }
+            
         }
 
-        private void NavigateToProperty(string btnName)
+        private void NavigateToProperty(string btnName, AnnotPropertyPanel annotPropertyPanel)
         {
             NavigationParameters values = new NavigationParameters();
             values.Add(ParameterNames.PDFViewer, PDFViewer);
-            regions.RequestNavigate(RegionNames.PropertyRegionName,btnToProperty[btnName]);
+            values.Add(ParameterNames.PropertyPanelContentViewModel, annotPropertyPanel);
+            values.Add("Shape", Shape);
+            values.Add("FillAndSignContentViewModel", this);
+            regions.RequestNavigate(RegionNames.PropertyRegionName,btnName,values);
             viewContentViewModel.IsPropertyOpen = true;
         }
 
@@ -317,107 +417,177 @@ namespace PDF_Office.ViewModels.FillAndSign
         {
             //来自PDFViewer的响应事件
             if (PDFViewer != null)
-            {
-                
-
-                PDFViewer.AnnotActiveHandler -= PDFViewer_AnnotActiveHandler;
-                PDFViewer.AnnotActiveHandler += PDFViewer_AnnotActiveHandler;
-
-            
+            {
+
+
+                //PDFViewer.AnnotActiveHandler -= PDFViewer_AnnotActiveHandler;
+                //PDFViewer.AnnotActiveHandler += PDFViewer_AnnotActiveHandler;
+
+
             }
         }
-
+        private void UnBindingPDFViewerHandler()
+        {
+            if (PDFViewer != null)
+            { /*PDFViewer.AnnotActiveHandler += PDFViewer_AnnotActiveHandler; */}
+        }
+
 
         //选中和非选中注释,右键菜单
-        private void PDFViewer_AnnotActiveHandler(object sender, AnnotAttribEvent e)
-        {
-            if (e != null)
-            {
-                var annot = e.AnnotItemsList[0];
-                if (annot != null)
-                {
-                    if (e.AnnotItemsList.Count == 1)
-                    {
-                        //IsAnnotCreateReset:是否为创建注释的状态
-                        if (e.IsAnnotCreateReset == false)
-                        {
-                            GetSelectedAnnots(e);
-                            //记录这次选中的注释,之后创建注释会跟随上次选中注释的属性值
-                            PDFViewer.SetToolParam(annot);
-                        }
-                        else
-                        {
-                            
-                            //TODO: 设计已重新调整为(仅限高亮注释):修改注释后,会作用到之后添加的注释中。因此先把此逻辑“创建注释后,会自动回到默认值”注释掉
-                            if (annot.EventType != AnnotArgsType.AnnotStrikeout &&
-                                annot.EventType != AnnotArgsType.AnnotUnderline &&
-                                annot.EventType != AnnotArgsType.AnnotHighlight &&
-                                annot.EventType != AnnotArgsType.AnnotSquiggly &&
-                                annot.EventType != AnnotArgsType.AnnotLink &&
-                                annot.EventType != AnnotArgsType.AnnotFreehand &&
-                                annot.EventType != AnnotArgsType.AnnotSticky
-                                )
-                            {
-                                if (ToolExpandDict.ContainsValue(e.AnnotItemsList[0].EventType))
-                                {
-                                    foreach (var item in ToolExpandDict)
-                                    {
-                                        if (item.Value == e.AnnotItemsList[0].EventType)
-                                        {
-                                            annot = null;//新建注释时,回到默认值
-                                            FindAnnotTypeKey(item.Key, ref annot);
-                                            break;
-                                        }
-                                    }
-                                }
-                            }
-                            //else
-                            PDFViewer.SetToolParam(annot);
-                            //设计重新调整,阅读页空白处,右键菜单,添加链接,和pro mac一样的效果,不显示属性栏
-                            if (isRightMenuAddAnnot)
-                            {
-                                ShowPropertyPanel(false);
-                            }
-                            else
-                            {
-                                ShowPropertyPanel();
-                            }
-                        }
-                    }
-                    else
-                    {
-                        bool isDifferentAnnotTyle = false;
-                        var lastAnnot = annot;
-                        foreach (var item in e.AnnotItemsList)
-                        {
-                            if (lastAnnot.EventType != item.EventType)
-                            {
-                                if (isShapAnnot(annot) == true && isShapAnnot(item) == true)
-                                {
-                                    lastAnnot = item;
-                                    continue;
-                                }
-
-                                lastAnnot = item;
-                                isDifferentAnnotTyle = true;
-                                break;
-                            }
-                        }
-
-
-                        if (isDifferentAnnotTyle)
-                            viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
-                        else
-                            GetSelectedAnnots(e);
-                    }
-
-                }
-            }
-            else
-            {
-                viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
-            }
-        }
+        //private void PDFViewer_AnnotActiveHandler(object sender, AnnotAttribEvent e)
+        //{
+        //    if (e != null)
+        //    {
+        //        var annot = e.AnnotItemsList[0];
+        //        if (annot != null)
+        //        {
+        //            if (e.AnnotItemsList.Count == 1)
+        //            {
+        //                //IsAnnotCreateReset:是否为创建注释的状态
+        //                if (e.IsAnnotCreateReset == false)
+        //                {
+        //                    GetSelectedAnnots(e);
+        //                    //记录这次选中的注释,之后创建注释会跟随上次选中注释的属性值
+        //                    PDFViewer.SetToolParam(annot);
+        //                }
+        //                else
+        //                {
+
+        //                    //TODO: 设计已重新调整为(仅限高亮注释):修改注释后,会作用到之后添加的注释中。因此先把此逻辑“创建注释后,会自动回到默认值”注释掉
+        //                    if (annot.EventType != AnnotArgsType.AnnotStrikeout &&
+        //                        annot.EventType != AnnotArgsType.AnnotUnderline &&
+        //                        annot.EventType != AnnotArgsType.AnnotHighlight &&
+        //                        annot.EventType != AnnotArgsType.AnnotSquiggly &&
+        //                        annot.EventType != AnnotArgsType.AnnotLink &&
+        //                        annot.EventType != AnnotArgsType.AnnotFreehand &&
+        //                        annot.EventType != AnnotArgsType.AnnotSticky
+        //                        )
+        //                    {
+        //                        if (ToolExpandDict.ContainsValue(e.AnnotItemsList[0].EventType))
+        //                        {
+        //                            foreach (var item in ToolExpandDict)
+        //                            {
+        //                                if (item.Value == e.AnnotItemsList[0].EventType)
+        //                                {
+        //                                    annot = null;//新建注释时,回到默认值
+        //                                    FindAnnotTypeKey(item.Key, ref annot);
+        //                                    break;
+        //                                }
+        //                            }
+        //                        }
+        //                    }
+        //                    //else
+        //                    //PDFViewer.SetToolParam(annot);
+        //                    //设计重新调整,阅读页空白处,右键菜单,添加链接,和pro mac一样的效果,不显示属性栏
+        //                    if (isRightMenuAddAnnot)
+        //                    {
+        //                        ShowPropertyPanel(false);
+        //                    }
+        //                    else
+        //                    {
+        //                        ShowPropertyPanel();
+        //                    }
+        //                }
+        //            }
+        //            else
+        //            {
+        //                bool isDifferentAnnotTyle = false;
+        //                var lastAnnot = annot;
+        //                foreach (var item in e.AnnotItemsList)
+        //                {
+        //                    if (lastAnnot.EventType != item.EventType)
+        //                    {
+        //                        if (isShapAnnot(annot) == true && isShapAnnot(item) == true)
+        //                        {
+        //                            lastAnnot = item;
+        //                            continue;
+        //                        }
+
+        //                        lastAnnot = item;
+        //                        isDifferentAnnotTyle = true;
+        //                        break;
+        //                    }
+        //                }
+
+
+        //                if (isDifferentAnnotTyle)
+        //                    viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
+        //                else
+        //                    GetSelectedAnnots(e);
+        //            }
+
+        //        }
+        //    }
+        //    else
+        //    {
+        //        viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
+        //    }
+        //}
+        //private void PDFViewer_AnnotEditHandler(object sender, List<AnnotEditEvent> e)
+        //{
+        //    if (e != null && e.Count > 0)
+        //    {
+        //        for (int i = 0; i < e.Count; i++)
+        //        {
+        //            AnnotEditEvent editEvent = e[i];
+        //            switch (editEvent.EditAction)
+        //            {
+        //                case ActionType.Add:
+
+        //                   // bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
+
+        //                    if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true)
+        //                    {
+        //                        AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel);
+
+        //                        if (viewModel != null)
+        //                        {
+        //                            int pageindex = editEvent.PageIndex;
+        //                            int annotindex = editEvent.AnnotIndex;
+        //                            viewModel.UpdateAddedAnnot(pageindex, annotindex);
+        //                        }
+        //                    }
+        //                    break;
+
+        //                case ActionType.Del:
+        //                    //isTabItemAnnotation = IsBOTATabItemShow(out bOTAContentViewModel, out bOTAContent, "TabItemAnnotation");
+        //                    if (isTabItemAnnotation)
+        //                    {
+        //                        AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel);
+
+        //                        if (viewModel != null)
+        //                        {
+        //                            int pageindex = editEvent.PageIndex;
+        //                            int annotindex = editEvent.AnnotIndex;
+        //                            viewModel.UpdateModifiedAnnot(pageindex, annotindex, true);
+        //                        }
+        //                    }
+        //                    break;
+
+        //                case ActionType.Modify:
+        //                    isTabItemAnnotation = IsBOTATabItemShow(out bOTAContentViewModel, out bOTAContent, "TabItemAnnotation");
+        //                    if (bOTAContent.TabItemAnnotation.IsSelected)
+        //                    {
+        //                        AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel);
+
+        //                        if (viewModel != null)
+        //                        {
+        //                            int pageindex = editEvent.PageIndex;
+        //                            int annotindex = editEvent.AnnotIndex;
+        //                            viewModel.UpdateModifiedAnnot(pageindex, annotindex, false);
+        //                        }
+        //                    }
+        //                    break;
+
+        //                case ActionType.TextEdit:
+        //                    break;
+
+        //                default:
+        //                    break;
+        //            }
+        //        }
+        //    }
+        //}
         private bool isShapAnnot(AnnotHandlerEventArgs annot)
         {
             if (annot.EventType == AnnotArgsType.AnnotCircle ||
@@ -436,17 +606,17 @@ namespace PDF_Office.ViewModels.FillAndSign
         {
             var annot = e.AnnotItemsList[0];
             switch (annot.EventType)
-            {
-                
-
-
+            {
+
+
+
                 case AnnotArgsType.AnnotFreeText:
                     GetFreetext(e.AnnotItemsList);
-                    break;
-
-                
-
-           
+                    break;
+
+
+
+
             }
         }
         private void ShowPropertyPanel(bool show = true)
@@ -463,7 +633,7 @@ namespace PDF_Office.ViewModels.FillAndSign
 
         public void OnNavigatedFrom(NavigationContext navigationContext)
         {
-
+            UnBindingPDFViewerHandler();
         }
 
         public void OnNavigatedTo(NavigationContext navigationContext)

+ 124 - 19
PDF Office/ViewModels/FillAndSign/PropertyPanel/ShapFillPropertyViewModel.cs

@@ -13,12 +13,21 @@ using Prism.Commands;
 using System.Windows.Controls;
 using ComPDFKit.PDFAnnotation;
 using PDF_Office.Helper;
+using System.Diagnostics;
+using PDF_Office.Model;
+using PDF_Office.ViewModels.Tools;
+using Microsoft.Office.Interop.Excel;
+using Point = System.Windows.Point;
 
 namespace PDF_Office.ViewModels.FillAndSign.PropertyPanel
 {
     public class ShapFillPropertyViewModel : BindableBase, INavigationAware
     {
-
+        public AnnotAttribEvent AnnotEvent { get; set; }
+        private AnnotHandlerEventArgs Annot;
+        private AnnotPropertyPanel PropertyPanel;
+        private FillAndSignContentViewModel fillAndSignContentViewModel;
+        
         private Geometry dataPath = null;
         public Geometry DataPath
         {
@@ -35,9 +44,10 @@ namespace PDF_Office.ViewModels.FillAndSign.PropertyPanel
             get { return selectColor; }
             set
             {
-                SetProperty(ref selectColor, value);
-                //AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, (selectColor as SolidColorBrush).Color);
-                //AnnotEvent?.UpdateAnnot();
+                SetProperty(ref selectColor, value); 
+                fillAndSignContentViewModel.SelectColor = value;
+                fillAndSignContentViewModel.SetStamp();
+               
             }
         }
 
@@ -48,9 +58,19 @@ namespace PDF_Office.ViewModels.FillAndSign.PropertyPanel
             set
             {
                 SetProperty(ref fillOpacity, value);
+                fillAndSignContentViewModel.FillOpacity = value;
+                fillAndSignContentViewModel.SetStamp( );
+                
             }
         }
 
+        private bool _isMultiSelected = false;
+        public bool IsMultiSelected
+        {
+            get { return _isMultiSelected; }
+            set => SetProperty(ref _isMultiSelected, value);
+        }
+
         private double lineWidth = 1;
         public double LineWidth
         {
@@ -58,13 +78,9 @@ namespace PDF_Office.ViewModels.FillAndSign.PropertyPanel
             set
             {
                 SetProperty(ref lineWidth, value);
-
-                //if (annotType == AnnotArgsType.AnnotLine)
-                //    AnnotEvent?.UpdateAttrib(AnnotAttrib.Thickness, lineWidth);
-                //else
-                //    AnnotEvent?.UpdateAttrib(AnnotAttrib.Thickness, lineWidth);
-
-                //AnnotEvent?.UpdateAnnot();
+                fillAndSignContentViewModel.LineWidth = value;
+                fillAndSignContentViewModel.SetStamp();
+                
             }
         }
         public DelegateCommand<object> SelectedThickCommand { get; set; }
@@ -103,14 +119,13 @@ namespace PDF_Office.ViewModels.FillAndSign.PropertyPanel
                 case "HookShape":
                     var hookShape = new PathGeometry();
                     hookShape.AddGeometry(Geometry.Parse("M0.599976 7.0286L5.57775 11.8L13.4 1.40002"));
-
                     DataPath = hookShape;
                     changeData[AnnotArgsType.AnnotLine] = tag;
                     break;
 
                 case "ForkShape":
                     var forkShape = new PathGeometry();
-                    forkShape.AddGeometry(Geometry.Parse(" M3.19995 3.20001L12.8 12.8 M12.8 3.20001L3.20005 12.8"));
+                    forkShape.AddGeometry(Geometry.Parse("M3.19995 3.20001L12.8 12.8 M12.8 3.20001L3.20005 12.8"));
                     DataPath = forkShape;
                     changeData[AnnotArgsType.AnnotLine] = tag;
                     break;
@@ -150,7 +165,59 @@ namespace PDF_Office.ViewModels.FillAndSign.PropertyPanel
             //if (isFromToolsBtn == false)
             //    PropertyPanel.AnnotTypeChangedInvoke(this, changeData);
 
+        }
+
+        private void InitSharpsType(string tag)
+        {
+            
+            switch (tag)
+            {
+                case "HookShape":
+                    var hookShape = new PathGeometry();
+                    hookShape.AddGeometry(Geometry.Parse("M0.599976 7.0286L5.57775 11.8L13.4 1.40002"));
+                    DataPath = hookShape;
+                    break;
+
+                case "ForkShape":
+                    var forkShape = new PathGeometry();
+                    forkShape.AddGeometry(Geometry.Parse("M3.19995 3.20001L12.8 12.8 M12.8 3.20001L3.20005 12.8"));
+                    DataPath = forkShape;
+                    break;
+
+                case "RectShape":
+                    {
+                        RectangleGeometry rectPath = new RectangleGeometry();
+                        rectPath.Rect = new Rect(0, 5, 28, 22);
+                        DataPath = rectPath;
+                    }
+
+                    break;
+                case "LineShape":
+                    {
+                        var lineShape = new PathGeometry();
+                        lineShape.AddGeometry(Geometry.Parse(" M0,10L20,10"));
+                        DataPath = lineShape;
+                    }
+
+                    break;
+
+                case "DotShape":
+                    {
+                        EllipseGeometry circlePath = new EllipseGeometry();
+                        circlePath.RadiusX = 2.4;
+                        circlePath.RadiusY = 2.4;
+                        circlePath.Center = new Point(2.4, 2.4);
+                        DataPath = circlePath;
+                    }
+
+                    break;
+            }
+
+            //if (isFromToolsBtn == false)
+            //    PropertyPanel.AnnotTypeChangedInvoke(this, changeData);
+
         }
+
         private void SelectedThick_Command(object obj)
         {
             if (obj is double)
@@ -158,7 +225,6 @@ namespace PDF_Office.ViewModels.FillAndSign.PropertyPanel
                 var tran = (double)obj;
                 //BorderOpacity = tran;
                 SelectColor.Opacity = tran;
-
                 //AnnotEvent?.UpdateAttrib(AnnotAttrib.Transparency, tran);
                 //AnnotEvent?.UpdateAnnot();
             }
@@ -212,8 +278,6 @@ namespace PDF_Office.ViewModels.FillAndSign.PropertyPanel
             }
 
         }
-
-        
 
         public bool IsNavigationTarget(NavigationContext navigationContext)
         {
@@ -227,9 +291,50 @@ namespace PDF_Office.ViewModels.FillAndSign.PropertyPanel
 
         public void OnNavigatedTo(NavigationContext navigationContext)
         {
-            RectangleGeometry rectPath = new RectangleGeometry();
-            rectPath.Rect = new Rect(0, 5, 28, 22);
-            DataPath = rectPath;
+            string shape = "";
+            navigationContext.Parameters.TryGetValue<AnnotPropertyPanel>(ParameterNames.PropertyPanelContentViewModel, out PropertyPanel);
+            navigationContext.Parameters.TryGetValue<FillAndSignContentViewModel>("FillAndSignContentViewModel", out fillAndSignContentViewModel);
+            navigationContext.Parameters.TryGetValue<string>("Shape", out shape);
+            InitSharpsType(shape);
+            
+            if (PropertyPanel != null)
+            {
+                AnnotEvent = PropertyPanel.AnnotEvent;
+                Annot = PropertyPanel.annot;
+                var stampAnnotArgs = Annot as StampAnnotArgs;
+                if (PropertyPanel.annotlists != null && PropertyPanel.annotlists.Count > 1)
+                {
+                    IsMultiSelected = true;
+                }
+                else
+                {
+                    IsMultiSelected = false;
+                }
+
+                if (IsMultiSelected)
+                {
+
+                }
+                else
+                {
+                    GetAnnotProperty();
+                }
+
+            }
+        }
+
+        private void GetAnnotProperty()
+        {
+            if (Annot is StickyAnnotArgs)
+            {
+                var annot = Annot as StickyAnnotArgs;
+                if (annot != null)
+                {
+                    SelectColor = new SolidColorBrush(annot.Color);
+                    FillOpacity = annot.Transparency;
+                }
+
+            }
         }
     }
 }

+ 5 - 3
PDF Office/Views/FillAndSign/PropertyPanel/ShapFillProperty.xaml

@@ -14,6 +14,7 @@
     d:DesignHeight="450"
     d:DesignWidth="260"
     prism:ViewModelLocator.AutoWireViewModel="True"
+    
     mc:Ignorable="d">
     <UserControl.Resources>
         <ResourceDictionary>
@@ -184,14 +185,15 @@
             </Grid>
 
             <Border
+                Visibility="Hidden"
                 Width="228"
                 Height="32"
                 Margin="0,12,0,0"
                 BorderBrush="#FFE2E3E6"
                 BorderThickness="1" 
-                Visibility="{Binding IsMultiSelected,Converter={StaticResource InvertBoolToVisibleConvert}}"
-                >
-                <Grid Name="ToolGrid">
+               
+                > <!--Visibility="{Binding IsMultiSelected,Converter={StaticResource InvertBoolToVisibleConvert}}"-->
+                <Grid Name="ToolGrid" >
                     <Grid.ColumnDefinitions>
                         <ColumnDefinition Width="40.5" />
                         <ColumnDefinition Width="40.5" />