Browse Source

Merge branch 'practice' of http://git.kdan.cc:8865/Windows/PDFOffice_Windows_exe into practice

liuaoran 2 years ago
parent
commit
dace6978b3

+ 5 - 1
PDF Office/EventAggregators/EditToolsEvent.cs

@@ -74,5 +74,9 @@ namespace PDF_Office.EventAggregators
     public class SaveBackgroundTemplateEvent : PubSubEvent<EnumColorOrFile>
     {
     }
-     
+
+    public class SaveWatermarkTemplateEvent : PubSubEvent<EnumTextOrFile>
+    {
+    }
+
 }

+ 0 - 1
PDF Office/ViewModels/EditTools/Background/BackgroundCreateFileContentViewModel.cs

@@ -124,7 +124,6 @@ namespace PDF_Office.ViewModels.EditTools.Background
             BackgroundInfo.Horizalign = C_Background_Horizalign.BG_HORIZALIGN_CENTER;
             BackgroundInfo.Vertalign = C_Background_Vertalign.BG_VERTALIGN_CENTER;
             InitLocationButtonMatrix();
-
             OpenFileCommand = new DelegateCommand(OpenFile);
             eventAggregator.GetEvent<ConfirmEditToolsBackgroundEvent>().Subscribe(ConfirmEditTools);
             eventAggregator.GetEvent<SaveBackgroundTemplateEvent>().Subscribe(SaveBackgroundTemplate);

+ 16 - 0
PDF Office/ViewModels/EditTools/Watermark/WatermarkCreateBaseContentViewModel.cs

@@ -52,8 +52,11 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
         }
 
         public DelegateCommand<object> ChangeCreateModCommand { get; set; }
+
         public DelegateCommand EnterTemplateListCommand { get; set; }
 
+        public DelegateCommand SaveToTemplateListCommand { get; set; }
+
         public WatermarkCreateBaseContentViewModel(IRegionManager regionManager, IEventAggregator eventAggregator)
         {
             this.eventAggregator = eventAggregator;
@@ -61,6 +64,19 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
             WatermarkCreateRegionName = Guid.NewGuid().ToString();
             ChangeCreateModCommand = new DelegateCommand<object>(ChangeCreateMod);
             EnterTemplateListCommand = new DelegateCommand(EnterTemplateList);
+            SaveToTemplateListCommand = new DelegateCommand(SaveToTemplateList);
+        }
+
+        public void SaveToTemplateList()
+        {
+            if (CurrentCreateModName == "WatermarkCreateTextContent")
+            {
+                this.eventAggregator.GetEvent<SaveWatermarkTemplateEvent>().Publish(EnumTextOrFile.StatusText);
+            }
+            if (CurrentCreateModName == "WatermarkCreateFileContent")
+            {
+                this.eventAggregator.GetEvent<SaveWatermarkTemplateEvent>().Publish(EnumTextOrFile.StatusFile);
+            }
         }
 
         public void EnterTemplateList()

+ 23 - 0
PDF Office/ViewModels/EditTools/Watermark/WatermarkCreateFileContentViewModel.cs

@@ -8,6 +8,8 @@ using PDF_Office.Helper;
 using PDF_Office.Model;
 using PDF_Office.Model.EditTools.Watermark;
 using PDF_Office.Model.PageEdit;
+using PDF_Office.Properties;
+using PDFSettings;
 using Prism.Commands;
 using Prism.Events;
 using Prism.Mvvm;
@@ -232,6 +234,7 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
             {
                 SetProperty(ref _isFrontSelectedIndex, value);
                 SetIsFront(IsFrontSelectedIndex);
+                eventAggregator.GetEvent<SetWatermarkEvent>().Publish(WatermarkInfo);
             }
         }
 
@@ -274,6 +277,26 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
             InitWatermarkInfo();
             InitLocationButtonMatrix();
             eventAggregator.GetEvent<ConfirmEditToolsWatermarkEvent>().Subscribe(ConfirmEditToolsWatermark);
+            eventAggregator.GetEvent<SaveWatermarkTemplateEvent>().Subscribe(SaveWatermarkTemplate);
+        }
+
+        public void SaveWatermarkTemplate(EnumTextOrFile enumTextOrFile)
+        {
+            if (enumTextOrFile == EnumTextOrFile.StatusFile && FileNameText!="")
+            {
+                SaveCurrentTemplate();
+            }
+        }
+
+        public void SaveCurrentTemplate()
+        {
+            var watermarkItem = new WatermarkItem();
+            watermarkItem.pageRange = "0";
+            watermarkItem.type = ComPDFKit.PDFWatermark.C_Watermark_Type.WATERMARK_TYPE_IMG;
+            watermarkItem.templateName += Settings.Default.BackgroundIndex.ToString();
+            Settings.Default.WatermarkTemplateList.Add(watermarkItem);
+            Settings.Default.Save();
+            this.eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Publish(EnumTemplateListOrCreate.StatusTemplate);
         }
 
         private void SetIsFront(int Index)

+ 30 - 5
PDF Office/ViewModels/EditTools/Watermark/WatermarkCreateTextContentViewModel.cs

@@ -8,6 +8,8 @@ using PDF_Office.Helper;
 using PDF_Office.Model;
 using PDF_Office.Model.EditTools.Background;
 using PDF_Office.Model.EditTools.Watermark;
+using PDF_Office.Properties;
+using PDFSettings;
 using Prism.Commands;
 using Prism.Events;
 using Prism.Mvvm;
@@ -155,9 +157,9 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
             get { return _textValue; }
             set
             {
-                SetProperty(ref _textValue, value);
-                WatermarkInfo.Text = TextValue;
-                eventAggregator.GetEvent<SetWatermarkEvent>().Publish(WatermarkInfo);
+             _textValue= value;
+               
+                
             }
         }
 
@@ -361,13 +363,34 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
             this.eventAggregator = eventAggregator;
             WatermarkInfo.WatermarkType = C_Watermark_Type.WATERMARK_TYPE_TEXT;
             ChangeLocationCommand = new DelegateCommand<object>(ChangeLocation);
-            SelectedColorChangedCommand = new DelegateCommand<object>(SelectedColorChanged_Click);
+            SelectedColorChangedCommand = new DelegateCommand<object>(ChangedColor);
             TextValueChangedCommand = new DelegateCommand<object>(TextValueChanged);
 
             InitList();
             InitWatermarkInfo();
             InitLocationButtonMatrix();
             eventAggregator.GetEvent<ConfirmEditToolsWatermarkEvent>().Subscribe(ConfirmEditToolsWatermark);
+
+            eventAggregator.GetEvent<SaveWatermarkTemplateEvent>().Subscribe(SaveWatermarkTemplate);
+        }
+
+        public void SaveWatermarkTemplate(EnumTextOrFile enumTextOrFile)
+        {
+            if (enumTextOrFile == EnumTextOrFile.StatusText)
+            {
+                SaveCurrentTemplate();
+            }
+        }
+
+        public void SaveCurrentTemplate()
+        {
+            var watermarkItem = new WatermarkItem();
+            watermarkItem.pageRange = "0";
+            watermarkItem.type = ComPDFKit.PDFWatermark.C_Watermark_Type.WATERMARK_TYPE_TEXT;
+            watermarkItem.templateName += Settings.Default.BackgroundIndex.ToString();
+            Settings.Default.WatermarkTemplateList.Add(watermarkItem);
+            Settings.Default.Save();
+            this.eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Publish(EnumTemplateListOrCreate.StatusTemplate);
         }
 
         private void InitLocationButtonMatrix()
@@ -398,7 +421,7 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
             }
         }
 
-        private void SelectedColorChanged_Click(object obj)
+        private void ChangedColor(object obj)
         {
             if (obj != null)
             {
@@ -419,6 +442,8 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
                 {
 
                     TextValue = textValue.Text;
+                    WatermarkInfo.Text = TextValue;
+                    eventAggregator.GetEvent<SetWatermarkEvent>().Publish(WatermarkInfo);
                 }
             }
 

+ 88 - 73
PDF Office/ViewModels/EditTools/Watermark/WatermarkDocumentContentViewModel.cs

@@ -23,6 +23,8 @@ using System.Windows;
 using ComPDFKitViewer;
 using Size = System.Windows.Size;
 using System.Diagnostics;
+using System.Windows.Controls;
+using ComPDFKit.Import;
 
 namespace PDF_Office.ViewModels.EditTools.Watermark
 {
@@ -34,6 +36,8 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
         public CPDFViewer PDFViewer;
         public CPDFDocument Document;
         private CPDFWatermark watermark;
+
+        private CPDFBackground background;
         private WatermarkInfo watermarkInfo;
 
 
@@ -63,79 +67,75 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
         public void SetWatermark(WatermarkInfo watermarkInfo)
         {
             this.watermarkInfo = watermarkInfo;
-            // CreateWatermark(PDFViewer.Document);
-            PDFViewer.Document.PdfToImage("0-1", "C:\\Users\\kdanmobile\\Desktop\\888");
-            PDFViewer.Document.WriteToFilePath("C:\\Users\\kdanmobile\\Desktop\\888\\sb22222.pdf");
-            PDFViewer.InvalidateVisual();
+            //CreateWatermark(PDFViewer.Document);
+            //PDFViewer.Document.PdfToImage("0-1", "C:\\Users\\kdanmobile\\Desktop\\888\\");
+            //PDFViewer.Document.WriteToFilePath("C:\\Users\\kdanmobile\\Desktop\\888\\sb22222.pdf");
+            PDFViewer.InvalidChildVisual(false);
         }
 
-        public void CreateWatermark(CPDFDocument document)
+        public void CreateWatermark(CPDFDocument document, bool IsNewDoc = false)
         {
-            if (watermarkInfo != null)
-            {
-                document.DeleteWatermarks();
-                if (watermarkInfo.WatermarkType == C_Watermark_Type.WATERMARK_TYPE_TEXT)
-                {
-                    watermark = document.InitWatermark(C_Watermark_Type.WATERMARK_TYPE_TEXT);
-                    watermark.SetText(watermarkInfo.Text);
-                    if (watermarkInfo.TextSize == null)
-                    {
-                        watermarkInfo.TextSize = "6";
-                    }
-                    watermark.SetFontName(watermarkInfo.FontName);
-                    watermark.SetFontSize(float.Parse(watermarkInfo.TextSize));
-                    watermark.SetTextRGBColor(watermarkInfo.TextColor);
-                }
-                else
-                {
-
-                    watermark = document.InitWatermark(C_Watermark_Type.WATERMARK_TYPE_IMG);
-                    if (watermarkInfo.ImageArray != null)
-                    {
-                        watermark.SetImage(watermarkInfo.ImageArray, watermarkInfo.ImageWidth, watermarkInfo.ImageHeight);
-                    }
-                    watermark.SetScale(0.1f);
-                }
-                watermark.SetRotation(watermarkInfo.Rotation);
-                watermark.SetOpacity(watermarkInfo.Opacity);
-                watermark.SetFront(watermarkInfo.IsFront);
-                watermark.SetVertalign(watermarkInfo.WatermarkVertalign);
-                watermark.SetHorizalign(watermarkInfo.WatermarkHorizalign);
-                watermark.SetFullScreen(watermarkInfo.Isfull);
-                watermark.SetVertOffset(watermarkInfo.VertOffset);
-                watermark.SetHorizOffset(watermarkInfo.HorizOffset);
-                watermark.SetHorizontalSpacing(watermarkInfo.HorizontalSpacing);
-                watermark.SetVerticalSpacing(watermarkInfo.VerticalSpacing);
-                watermark.SetPages(watermarkInfo.PageRange);
-                watermark.CreateWatermark();
-                watermark.UpdateWatermark();
-            }
+            if (watermarkInfo != null) { 
+                background = document.GetBackground();
+
+            background.SetBackgroundType(C_Background_Type.BG_TYPE_COLOR);
+
+            background.SetScale(1);
+            background.SetColor(watermarkInfo.TextColor);
+
+            background.SetRotation(0);
+            background.SetOpacity(255);
+            background.SetVertalign(C_Background_Vertalign.BG_VERTALIGN_CENTER);
+            background.SetHorizalign(C_Background_Horizalign.BG_HORIZALIGN_CENTER);
+            background.SetYOffset(0);
+            background.SetXOffset(0);
+            background.SetAllowsPrint(true);
+            background.SetAllowsView(true);
+            background.SetPages("0");
+            background.Update();
         }
-
-        public BitmapSource ToBitmapSource(System.Drawing.Bitmap image)
-        {
-            IntPtr ptr = image.GetHbitmap();//obtain the Hbitmap
-            BitmapSource bs = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap
-            (
-                ptr,
-                IntPtr.Zero,
-                Int32Rect.Empty,
-                System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions()
-            );
-
-            return bs;
+            //if (watermarkInfo != null)
+            //{
+            //    document.DeleteWatermarks();
+            //    if (watermarkInfo.WatermarkType == C_Watermark_Type.WATERMARK_TYPE_TEXT)
+            //    {
+            //        watermark = document.InitWatermark(C_Watermark_Type.WATERMARK_TYPE_TEXT);
+            //        watermark.SetText(watermarkInfo.Text);
+            //        if (watermarkInfo.TextSize == null)
+            //        {
+            //            watermarkInfo.TextSize = "6";
+            //        }
+            //        watermark.SetFontName(watermarkInfo.FontName);
+            //        watermark.SetFontSize(float.Parse(watermarkInfo.TextSize));
+            //        watermark.SetTextRGBColor(watermarkInfo.TextColor);
+            //    }
+            //    else
+            //    {
+
+            //        watermark = document.InitWatermark(C_Watermark_Type.WATERMARK_TYPE_IMG);
+            //        if (watermarkInfo.ImageArray != null)
+            //        {
+            //            watermark.SetImage(watermarkInfo.ImageArray, watermarkInfo.ImageWidth, watermarkInfo.ImageHeight);
+            //        }
+            //        watermark.SetScale(0.1f);
+            //    }
+            //    watermark.SetRotation(watermarkInfo.Rotation);
+            //    watermark.SetOpacity(watermarkInfo.Opacity);
+            //    watermark.SetFront(watermarkInfo.IsFront);
+            //    watermark.SetVertalign(watermarkInfo.WatermarkVertalign);
+            //    watermark.SetHorizalign(watermarkInfo.WatermarkHorizalign);
+            //    watermark.SetFullScreen(watermarkInfo.Isfull);
+            //    watermark.SetVertOffset(watermarkInfo.VertOffset);
+            //    watermark.SetHorizOffset(watermarkInfo.HorizOffset);
+            //    watermark.SetHorizontalSpacing(watermarkInfo.HorizontalSpacing);
+            //    watermark.SetVerticalSpacing(watermarkInfo.VerticalSpacing);
+            //    if (IsNewDoc) { watermark.SetPages("0");  }
+            //    else { watermark.SetPages(watermarkInfo.PageRange); }
+            //    watermark.CreateWatermark();
+            //    watermark.UpdateWatermark();
+            //}
         }
 
-        public async Task RenderBitmap(CPDFDocument doc)
-        {
-
-            CPDFPage page = doc.PageAtIndex(0, true);
-            byte[] bmp_data = new byte[(int)page.PageSize.Width * (int)page.PageSize.Height * 4];
-            Bitmap bitmap = await ToolMethod.RenderPageBitmap(Document, (int)(page.PageSize.Width * 1 * 1.4), (int)(page.PageSize.Height * 1 * 1.4), 0, true, true);
-            ImageSource = ToBitmapSource(bitmap);
-            doc.ReleasePages();
-
-        }
 
         private void UndoManager_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
         {
@@ -145,10 +145,27 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
         {
             if (e.DrawPages.Count > 0 && e.DrawContext != null)
             {
+                List<int> PageIndexLists = new List<int>();
                 foreach (DrawPageData drawPageData in e.DrawPages)
-                {
-                    WriteableBitmap waterMarkBitmap = GetWaterMark(PDFViewer.Document, e.Zoom, drawPageData.PageIndex);
-                    e.DrawContext.DrawImage(waterMarkBitmap, drawPageData.PageBound);
+                {   
+                    if(watermarkInfo != null) {
+                        char[] enumerationSeparator = new char[] { ',' };
+                        char[] rangeSeparator = new char[] { '-' };
+                        if (CommonHelper.GetPagesInRange(ref PageIndexLists, watermarkInfo.PageRange, Document.PageCount, enumerationSeparator, rangeSeparator, true))
+                        { //TODO
+                            Trace.WriteLine(CommonHelper.GetPagesInRange(ref PageIndexLists, watermarkInfo.PageRange, Document.PageCount, enumerationSeparator, rangeSeparator, true));
+                            Trace.WriteLine(drawPageData.PageIndex);
+                            foreach (var abbb in PageIndexLists ) {
+
+                                Trace.WriteLine("smgui _______"+abbb);
+                            }
+                            if (PageIndexLists.Contains(drawPageData.PageIndex-1)) {
+                                
+                                WriteableBitmap waterMarkBitmap = GetWaterMark(PDFViewer.Document, e.Zoom, drawPageData.PageIndex);
+                                e.DrawContext.DrawImage(waterMarkBitmap, drawPageData.PageBound);
+                            }
+                        }
+                    }
                 }
             }
         }
@@ -158,14 +175,12 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
 
             CPDFDocument newDoc = CPDFDocument.CreateDocument();
             newDoc.InsertPage(0, pageSize.Width, pageSize.Height, null);
-
-            CreateWatermark(newDoc);
+            CreateWatermark(newDoc,true);
             CPDFPage newPage = newDoc.PageAtIndex(0);
             double scale = 96.0 / 72.0;
             zoom = zoom * scale;
             Rect renderRect = new Rect(0, 0, (int)(pageSize.Width * scale), (int)(pageSize.Height * scale));
             byte[] imageArray = new byte[(int)(renderRect.Width * renderRect.Height * 4)];
-
             newPage.RenderPageBitmapWithMatrix((float)zoom, renderRect, 0x00FFFFFF, imageArray, 1, true);
             WriteableBitmap WirteBitmap = new WriteableBitmap((int)renderRect.Width, (int)renderRect.Height, 96, 96, PixelFormats.Bgra32, null);
             WirteBitmap.WritePixels(new Int32Rect(0, 0, (int)renderRect.Width, (int)renderRect.Height), imageArray, WirteBitmap.BackBufferStride, 0);

+ 55 - 20
PDF Office/ViewModels/EditTools/Watermark/WatermarkTemplateListFileContentViewModel.cs

@@ -1,6 +1,10 @@
-using PDF_Office.Properties;
+using PDF_Office.EventAggregators;
+using PDF_Office.Model.EditTools.Background;
+using PDF_Office.Model.EditTools.Watermark;
+using PDF_Office.Properties;
 using PDFSettings;
 using Prism.Commands;
+using Prism.Events;
 using Prism.Mvvm;
 using Prism.Regions;
 using System;
@@ -8,12 +12,15 @@ using System.Collections.Generic;
 using System.Collections.ObjectModel;
 using System.Linq;
 using System.Windows;
+using System.Windows.Controls;
 
 namespace PDF_Office.ViewModels.EditTools.Watermark
 {
     public class WatermarkTemplateListFileContentViewModel : BindableBase, INavigationAware
     {
-       
+        private readonly IEventAggregator eventAggregator;
+
+        public WatermarkInfo WatermarkInfo;
         public ObservableCollection<WatermarkItem> watermarkModFileCollection = new ObservableCollection<WatermarkItem>();
         public ObservableCollection<WatermarkItem> WatermarkModFileCollection
         {
@@ -34,11 +41,16 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
 
         public DelegateCommand AddTemplateCommand { get; set; }
         public DelegateCommand<object> DeleteTemplateItemCommand { get; set; }
+        public DelegateCommand DeleteAllTemplateItemCommand { get; set; }
+        public DelegateCommand<object> SelectTemplateItemCommand { get; set; }
 
-        public WatermarkTemplateListFileContentViewModel()
+        public WatermarkTemplateListFileContentViewModel(IEventAggregator eventAggregator)
         {
+            this.eventAggregator = eventAggregator;
             AddTemplateCommand = new DelegateCommand(AddTemplate);
             DeleteTemplateItemCommand = new DelegateCommand<object>(DeleteTemplateItem);
+            DeleteAllTemplateItemCommand = new DelegateCommand(DeleteAllTemplateItem);
+            SelectTemplateItemCommand = new DelegateCommand<object>(SelectTemplateItem);
         }
 
         private void CheckTemplateListIsEmpty(List<WatermarkItem> watermarkTemplateList)
@@ -60,8 +72,6 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
             {
                 if (Settings.Default.WatermarkTemplateList[temp].type == ComPDFKit.PDFWatermark.C_Watermark_Type.WATERMARK_TYPE_IMG)
                 {
-
-
                     watermarkModTextTemplateList.Add(Settings.Default.WatermarkTemplateList[temp]);
                 }
             }
@@ -80,19 +90,6 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
             GetWatermarkSource();
         }
 
-        private void UpdateWatermarkSources()
-        {
-            List<WatermarkItem> watermarkModTextTemplateList = new List<WatermarkItem>();
-            for (int temp = 0; temp < Settings.Default.WatermarkTemplateList.Count; temp++)
-            {
-                if (Settings.Default.WatermarkTemplateList[temp].type == ComPDFKit.PDFWatermark.C_Watermark_Type.WATERMARK_TYPE_IMG)
-                {
-                    watermarkModTextTemplateList.Add(Settings.Default.WatermarkTemplateList[temp]);
-                }
-            }
-            WatermarkModFileCollection = new ObservableCollection<WatermarkItem>(watermarkModTextTemplateList);
-            CheckTemplateListIsEmpty(watermarkModTextTemplateList);
-        }
 
         public void AddTemplate()
         {
@@ -102,7 +99,7 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
             watermarkItem.templateName += Settings.Default.WatermarkIndex.ToString();
             Settings.Default.WatermarkTemplateList.Add(watermarkItem);
             Settings.Default.Save();
-            UpdateWatermarkSources();
+            GetWatermarkSource();
         }
 
         public void DeleteTemplateItem(object e)
@@ -124,10 +121,47 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
             Settings.Default.Save();
 
             WatermarkModFileCollection.Remove(template);
-            UpdateWatermarkSources();
+            GetWatermarkSource();
 
         }
 
+        public void DeleteAllTemplateItem()
+        {
+            while (Settings.Default.WatermarkTemplateList.Count != 0)
+            {
+                int temp = 0;
+                var template = Settings.Default.WatermarkTemplateList[temp];
+                Settings.Default.AppProperties.NeedToDeletePath.Add(template.previeImagePath);
+                Settings.Default.AppProperties.NeedToDeletePath.Add(template.imagepath);
+
+                Settings.Default.WatermarkTemplateList.Remove(template);
+                Settings.Default.Save();
+
+                WatermarkModFileCollection.Remove(template);
+            }
+            GetWatermarkSource();
+        }
+
+        public void SelectTemplateItem(object e)
+        {
+            var listBox = e as ListBox;
+            WatermarkItem WatermarkItem = listBox.SelectedItem as WatermarkItem;
+            SendTemplateItemToDocument(WatermarkItem);
+        }
+
+        public void ConvertItemToInfo(WatermarkItem watermarkItem, ref WatermarkInfo watermarkInfo)
+        {
+
+        }
+
+        public void SendTemplateItemToDocument(WatermarkItem WatermarkItem)
+        {
+            ConvertItemToInfo(WatermarkItem, ref WatermarkInfo);
+            eventAggregator.GetEvent<SetWatermarkEvent>().Publish(WatermarkInfo);
+        }
+
+
+
         public bool IsNavigationTarget(NavigationContext navigationContext)
         {
             return true;
@@ -139,6 +173,7 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
 
         public void OnNavigatedTo(NavigationContext navigationContext)
         {
+            InitWatermarkTemplateList();
         }
     }
 }

+ 49 - 17
PDF Office/ViewModels/EditTools/Watermark/WatermarkTemplateListTextContentViewModel.cs

@@ -8,11 +8,17 @@ using System.Collections.Generic;
 using System.Collections.ObjectModel;
 using System.Linq;
 using PDF_Office.Properties;
+using Prism.Events;
+using PDF_Office.EventAggregators;
+using PDF_Office.Model.EditTools.Watermark;
+using System.Windows.Controls;
 
 namespace PDF_Office.ViewModels.EditTools.Watermark
 {
     public class WatermarkTemplateListTextContentViewModel : BindableBase, INavigationAware
     {
+        private readonly IEventAggregator eventAggregator;
+        public WatermarkInfo WatermarkInfo;
         public ObservableCollection<WatermarkItem> watermarkModTextCollection = new ObservableCollection<WatermarkItem>();
         public ObservableCollection<WatermarkItem> WatermarkModTextCollection
         {
@@ -33,11 +39,16 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
 
         public DelegateCommand AddTemplateCommand { get; set; }
         public DelegateCommand<object> DeleteTemplateItemCommand { get; set; }
+        public DelegateCommand DeleteAllTemplateItemCommand { get; set; }
+        public DelegateCommand<object> SelectTemplateItemCommand { get; set; }
 
-        public WatermarkTemplateListTextContentViewModel()
+        public WatermarkTemplateListTextContentViewModel(IEventAggregator eventAggregator)
         {
+            this.eventAggregator = eventAggregator;
             AddTemplateCommand = new DelegateCommand(AddTemplate);
             DeleteTemplateItemCommand = new DelegateCommand<object>(DeleteTemplateItem);
+            DeleteAllTemplateItemCommand = new DelegateCommand(DeleteAllTemplateItem);
+            SelectTemplateItemCommand = new DelegateCommand<object>(SelectTemplateItem);
         }
 
         private void CheckTemplateListIsEmpty(List<WatermarkItem>watermarkTemplateList)
@@ -79,20 +90,6 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
             GetWatermarkSource();
         }
 
-        private void UpdateWatermarkSources()
-        {
-            List<WatermarkItem>watermarkModTextTemplateList = new List<WatermarkItem>();
-            for (int temp = 0; temp < Settings.Default.WatermarkTemplateList.Count; temp++)
-            {
-                if (Settings.Default.WatermarkTemplateList[temp].type == ComPDFKit.PDFWatermark.C_Watermark_Type.WATERMARK_TYPE_TEXT)
-                {
-                   watermarkModTextTemplateList.Add(Settings.Default.WatermarkTemplateList[temp]);
-                }
-            }
-           WatermarkModTextCollection = new ObservableCollection<WatermarkItem>(watermarkModTextTemplateList);
-            CheckTemplateListIsEmpty(watermarkModTextTemplateList);
-        }
-
         public void AddTemplate()
         {
             var watermarkItem = new WatermarkItem();
@@ -101,7 +98,7 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
             watermarkItem.templateName += Settings.Default.WatermarkIndex.ToString();
             Settings.Default.WatermarkTemplateList.Add(watermarkItem);
             Settings.Default.Save();
-            UpdateWatermarkSources();
+            GetWatermarkSource();
         }
 
         public void DeleteTemplateItem(object e)
@@ -123,8 +120,43 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
             Settings.Default.Save();
 
             WatermarkModTextCollection.Remove(template);
-            UpdateWatermarkSources();
+            GetWatermarkSource();
+
+        }
 
+        public void DeleteAllTemplateItem()
+        {
+            while (Settings.Default.WatermarkTemplateList.Count != 0)
+            {
+                int temp = 0;
+                var template = Settings.Default.WatermarkTemplateList[temp];
+                Settings.Default.AppProperties.NeedToDeletePath.Add(template.previeImagePath);
+                Settings.Default.AppProperties.NeedToDeletePath.Add(template.imagepath);
+
+                Settings.Default.WatermarkTemplateList.Remove(template);
+                Settings.Default.Save();
+
+                WatermarkModTextCollection.Remove(template);
+            }
+            GetWatermarkSource();
+        }
+
+        public void SelectTemplateItem(object e)
+        {
+            var listBox = e as ListBox;
+            WatermarkItem WatermarkItem = listBox.SelectedItem as WatermarkItem;
+            SendTemplateItemToDocument(WatermarkItem);
+        }
+
+        public void ConvertItemToInfo(WatermarkItem watermarkItem, ref WatermarkInfo watermarkInfo)
+        {
+
+        }
+
+        public void SendTemplateItemToDocument(WatermarkItem WatermarkItem)
+        {
+            ConvertItemToInfo(WatermarkItem, ref WatermarkInfo);
+            eventAggregator.GetEvent<SetWatermarkEvent>().Publish(WatermarkInfo);
         }
 
         public bool IsNavigationTarget(NavigationContext navigationContext)

+ 1 - 1
PDF Office/Views/EditTools/Watermark/WatermarkCreateBaseContent.xaml

@@ -21,7 +21,7 @@
                     <TextBlock Text="创建水印" Margin="8,0,0,0" FontSize="16"></TextBlock>
                 </StackPanel>
             </Button>
-            <Button  Height="20" Width="64" Margin="0,0,16,0" HorizontalAlignment="Right" >
+            <Button  Height="20" Width="64" Margin="0,0,16,0" HorizontalAlignment="Right" Command="{Binding SaveToTemplateListCommand}">
                 <StackPanel>
                     <TextBlock Text="保存至模板" FontSize="12" Foreground="#18A0FB"></TextBlock>
                     <Rectangle Height="2" Fill="#18A0FB"></Rectangle>

+ 20 - 2
PDF Office/Views/EditTools/Watermark/WatermarkTemplateListFileContent.xaml

@@ -9,6 +9,23 @@
              mc:Ignorable="d"
              d:DesignHeight="632"
              d:DesignWidth="260">
+
+    <UserControl.Resources>
+        <ContextMenu x:Key="FlyoutMenu" FontSize="14" >
+            <ContextMenu.ItemContainerStyle>
+                <Style TargetType="{x:Type MenuItem}">
+                    <Setter Property="Padding" Value="0,8,0,8"/>
+                    <Setter Property="VerticalContentAlignment" Value="Center"/>
+                </Style>
+            </ContextMenu.ItemContainerStyle>
+            <MenuItem Name="MenuEdit" Header="编辑模板" Click="MenuEdit_Click" >
+            </MenuItem>
+            <MenuItem Name="MenuDeleteCurrent" Header="删除模板"  Click="MenuDeleteCurrent_Click">
+            </MenuItem>
+            <MenuItem Name="MenuDeleteAll" Header="删除全部" Click="MenuDeleteAll_Click"></MenuItem>
+        </ContextMenu>
+    </UserControl.Resources>
+    
     <Grid Background="#F3F3F3">
         <ListBox Name="FileWatermarkListbox" 
                                 Width="240" 
@@ -22,13 +39,14 @@
                                 VirtualizingPanel.CacheLength="1"
                                 VirtualizingPanel.ScrollUnit="Pixel"   
                                 Background="#F3F3F3"
-                 ItemsSource="{Binding WatermarkModFileCollection}">
+                 ItemsSource="{Binding WatermarkModFileCollection}"
+                 SelectionChanged="ListBox_SelectionChanged">
             <ListBox.ItemContainerStyle>
                 <Style TargetType="ListBoxItem">
                     <Setter Property="Margin" Value="0"/>
                     <Setter Property="Padding" Value="8 0 8 0"/>
                     <!--<Setter Property="ContextMenu" Value="{StaticResource FlyoutMenu}"/>-->
-                    <Setter Property="Template" Value="{DynamicResource ListBoxItemControlTemplate}"/>
+                    <Setter Property="Template" Value="{DynamicResource EditToolsItemControlTemplate}"/>
                 </Style>
             </ListBox.ItemContainerStyle>
             <ListBox.ItemTemplate>

+ 22 - 0
PDF Office/Views/EditTools/Watermark/WatermarkTemplateListFileContent.xaml.cs

@@ -1,5 +1,6 @@
 using ComPDFKitViewer;
 using PDF_Office.ViewModels.EditTools.Watermark;
+using System.Windows;
 using System.Windows.Controls;
 
 namespace PDF_Office.Views.EditTools.Watermark
@@ -20,5 +21,26 @@ namespace PDF_Office.Views.EditTools.Watermark
         {
             viewModel.DeleteTemplateItemCommand?.Execute(sender);
         }
+
+        private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
+        {
+            viewModel.SelectTemplateItemCommand?.Execute(sender);
+        }
+
+        private void MenuEdit_Click(object sender, RoutedEventArgs e)
+        {
+
+        }
+
+        private void MenuDeleteCurrent_Click(object sender, RoutedEventArgs e)
+        {
+            viewModel.DeleteTemplateItemCommand?.Execute(sender);
+
+        }
+
+        private void MenuDeleteAll_Click(object sender, RoutedEventArgs e)
+        {
+            viewModel.DeleteAllTemplateItemCommand?.Execute();
+        }
     }
 }

+ 20 - 2
PDF Office/Views/EditTools/Watermark/WatermarkTemplateListTextContent.xaml

@@ -9,6 +9,23 @@
              mc:Ignorable="d"
              d:DesignHeight="632"
              d:DesignWidth="260">
+
+    <UserControl.Resources>
+        <ContextMenu x:Key="FlyoutMenu" FontSize="14" >
+            <ContextMenu.ItemContainerStyle>
+                <Style TargetType="{x:Type MenuItem}">
+                    <Setter Property="Padding" Value="0,8,0,8"/>
+                    <Setter Property="VerticalContentAlignment" Value="Center"/>
+                </Style>
+            </ContextMenu.ItemContainerStyle>
+            <MenuItem Name="MenuEdit" Header="编辑模板" Click="MenuEdit_Click" >
+            </MenuItem>
+            <MenuItem Name="MenuDeleteCurrent" Header="删除模板"  Click="MenuDeleteCurrent_Click">
+            </MenuItem>
+            <MenuItem Name="MenuDeleteAll" Header="删除全部" Click="MenuDeleteAll_Click"></MenuItem>
+        </ContextMenu>
+    </UserControl.Resources>
+    
     <Grid Background="#F3F3F3">
         <ListBox Name="TextWatermarkListbox" 
                                 Width="240" 
@@ -22,13 +39,14 @@
                                 VirtualizingPanel.CacheLength="1"
                                 VirtualizingPanel.ScrollUnit="Pixel"   
                                 Background="#F3F3F3"
-                 ItemsSource="{Binding WatermarkModTextCollection}">
+                 ItemsSource="{Binding WatermarkModTextCollection}"
+                 SelectionChanged="ListBox_SelectionChanged">
             <ListBox.ItemContainerStyle>
                 <Style TargetType="ListBoxItem">
                     <Setter Property="Margin" Value="0"/>
                     <Setter Property="Padding" Value="8 0 8 0"/>
                     <!--<Setter Property="ContextMenu" Value="{StaticResource FlyoutMenu}"/>-->
-                    <Setter Property="Template" Value="{DynamicResource ListBoxItemControlTemplate}"/>
+                    <Setter Property="Template" Value="{DynamicResource EditToolsItemControlTemplate}"/>
                 </Style>
             </ListBox.ItemContainerStyle>
             <ListBox.ItemTemplate>

+ 23 - 0
PDF Office/Views/EditTools/Watermark/WatermarkTemplateListTextContent.xaml.cs

@@ -1,5 +1,6 @@
 using ComPDFKitViewer;
 using PDF_Office.ViewModels.EditTools.Watermark;
+using System.Windows;
 using System.Windows.Controls;
 
 namespace PDF_Office.Views.EditTools.Watermark
@@ -20,5 +21,27 @@ namespace PDF_Office.Views.EditTools.Watermark
         {
             viewModel.DeleteTemplateItemCommand?.Execute(sender);
         }
+
+
+        private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
+        {
+            viewModel.SelectTemplateItemCommand?.Execute(sender);
+        }
+
+        private void MenuEdit_Click(object sender, RoutedEventArgs e)
+        {
+
+        }
+
+        private void MenuDeleteCurrent_Click(object sender, RoutedEventArgs e)
+        {
+            viewModel.DeleteTemplateItemCommand?.Execute(sender);
+
+        }
+
+        private void MenuDeleteAll_Click(object sender, RoutedEventArgs e)
+        {
+            viewModel.DeleteAllTemplateItemCommand?.Execute();
+        }
     }
 }