Browse Source

模板-渲染,设置接口

liuaoran 2 years ago
parent
commit
458bde923c

+ 21 - 21
PDF Office/App.config

@@ -1,22 +1,22 @@
-<?xml version="1.0" encoding="utf-8"?>
-<configuration>
-    <configSections>
-        <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
-            <section name="PDF_Office.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
-        </sectionGroup>
-    </configSections>
-    <startup> 
-        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" />
-    </startup>
-  <runtime>
-    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
-      <dependentAssembly>
-        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
-        <bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
-      </dependentAssembly>
-    </assemblyBinding>
-  </runtime>
-  <userSettings>
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+    <configSections>
+        <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
+            <section name="PDF_Office.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
+        </sectionGroup>
+    </configSections>
+    <startup> 
+        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" />
+    </startup>
+  <runtime>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+  </runtime>
+  <userSettings>
     <PDF_Office.Properties.Settings>
         <setting name="BackgroundIndex" serializeAs="String">
             <value>0</value>
@@ -24,6 +24,6 @@
         <setting name="WatermarkIndex" serializeAs="String">
             <value>0</value>
         </setting>
-    </PDF_Office.Properties.Settings>
-  </userSettings>
+    </PDF_Office.Properties.Settings>
+  </userSettings>
 </configuration>

+ 8 - 0
PDF Office/Model/RegionNames.cs

@@ -50,6 +50,14 @@ namespace PDF_Office.Model
             }
         }
 
+        public static string BackgroundViewRegionName
+        {
+            get
+            {
+                return GetRegionName("BackgroundViewerRegionName");
+            }
+        }
+
         /// <summary>
         /// BOTA内容项 对应的Content RegionName
         /// </summary>

+ 27 - 5
PDF Office/Styles/ListBoxStyle.xaml

@@ -48,22 +48,44 @@
         </ControlTemplate.Triggers>
     </ControlTemplate>
 
-    <ControlTemplate x:Key="EditToolsItemControlTemplate" TargetType="{x:Type ListBox}">
-        <Border x:Name="EditToolsBorder" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="True">
-            <ContentPresenter ContentTemplate="{Binding ContentTemplate}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
+    <ControlTemplate x:Key="EditToolsItemControlTemplate" TargetType="{x:Type ListBoxItem}">
+        <Border x:Name="EditToolsBorder"  
+            Padding="{TemplateBinding Padding}"
+            Background="{TemplateBinding Background}"
+            BorderBrush="{TemplateBinding BorderBrush}"
+            BorderThickness="{TemplateBinding BorderThickness}"
+            Height="{TemplateBinding Height}"
+            Width="{TemplateBinding Width}"
+            SnapsToDevicePixels="True"
+               >
+            <ContentPresenter   
+                Content="{TemplateBinding Content}"
+                ContentStringFormat="{TemplateBinding ContentStringFormat}"
+                ContentTemplate="{TemplateBinding ContentTemplate}"
+                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
         </Border>
         <ControlTemplate.Triggers>
             <MultiTrigger>
                 <MultiTrigger.Conditions>
                     <Condition Property="IsMouseOver" Value="True"></Condition>
                 </MultiTrigger.Conditions>
-                <Setter Property="Background" TargetName="EditToolsBorder" Value="#1A000000"/>
-                <Setter Property="BorderBrush" TargetName="EditToolsBorder" Value="Transparent"/>
+                <Setter Property="Background" TargetName="EditToolsBorder" Value="#1A477EDE"/>
+                <Setter Property="BorderBrush" TargetName="EditToolsBorder" Value="Black"/>
+            </MultiTrigger>
+            <MultiTrigger>
+                <MultiTrigger.Conditions>
+                    <Condition Property="Selector.IsSelectionActive" Value="True"/>
+                    <Condition Property="IsSelected" Value="True"/>
+                </MultiTrigger.Conditions>
+                <Setter Property="Background" TargetName="EditToolsBorder" Value="#1A477EDE"/>
+                <Setter Property="BorderBrush" TargetName="EditToolsBorder" Value="Black"/>
             </MultiTrigger>
             <Trigger Property="IsEnabled" Value="False">
                 <Setter Property="TextElement.Foreground" TargetName="EditToolsBorder" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
             </Trigger>
+
         </ControlTemplate.Triggers>
+
     </ControlTemplate>
 
 </ResourceDictionary>

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

@@ -6,6 +6,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;
@@ -125,6 +127,8 @@ namespace PDF_Office.ViewModels.EditTools.Background
 
             OpenFileCommand = new DelegateCommand(OpenFile);
             eventAggregator.GetEvent<ConfirmEditToolsBackgroundEvent>().Subscribe(ConfirmEditTools);
+            eventAggregator.GetEvent<SaveBackgroundTemplateEvent>().Subscribe(SaveBackgroundTemplate);
+
         }
 
         public string PageRangeText { get; set; } = "0";
@@ -247,6 +251,25 @@ namespace PDF_Office.ViewModels.EditTools.Background
             document.Release();
         }
 
+        public void SaveCurrentTemplate()
+        {
+            var backgroundItem = new BackgroundItem();
+            backgroundItem.pageRange = "0";
+            backgroundItem.type = ComPDFKit.PDFDocument.C_Background_Type.BG_TYPE_IMAGE;
+            backgroundItem.templateName += Settings.Default.BackgroundIndex.ToString();
+            Settings.Default.BackgroundTemplateList.Add(backgroundItem);
+            Settings.Default.Save();
+            this.eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Publish(EnumTemplateListOrCreate.StatusTemplate);
+        }
+
+        public void SaveBackgroundTemplate(EnumColorOrFile enumColorOrFile)
+        {
+            if (enumColorOrFile == EnumColorOrFile.StatusFile)
+            {
+                SaveCurrentTemplate();
+            }
+        }
+
         public bool IsNavigationTarget(NavigationContext navigationContext)
         {
             return true;

+ 77 - 19
PDF Office/ViewModels/EditTools/Background/BackgroundDocumentContentViewModel.cs

@@ -1,5 +1,6 @@
 using ComPDFKit.PDFDocument;
 using ComPDFKit.PDFPage;
+using ComPDFKitViewer;
 using ComPDFKitViewer.PdfViewer;
 using PDF_Office.EventAggregators;
 using PDF_Office.Helper;
@@ -20,12 +21,16 @@ using System.Windows.Media.Imaging;
 
 namespace PDF_Office.ViewModels.EditTools.Background
 {
-    public class BackgroundDocumentContentViewModel : BindableBase,INavigationAware
+    public class BackgroundDocumentContentViewModel : BindableBase, INavigationAware
     {
         public IEventAggregator eventAggregator;
+        public IRegionManager regionManager;
         public CPDFViewer PDFViewer;
-        public CPDFDocument document;
+        public CPDFDocument Document;
         public CPDFBackground background;
+        private BackgroundInfo BackgroundInfo;
+
+        public string ViewerRegionName { get; set; }
 
 
         private ImageSource _imageSource = null;
@@ -39,10 +44,12 @@ namespace PDF_Office.ViewModels.EditTools.Background
         }
 
 
-        public BackgroundDocumentContentViewModel(IEventAggregator  eventAggregator)
+        public BackgroundDocumentContentViewModel(IEventAggregator eventAggregator, IRegionManager regionManager)
         {
             this.eventAggregator = eventAggregator;
+            this.regionManager = regionManager;
             eventAggregator.GetEvent<SetBackgroundEvent>().Subscribe(SetBackground);
+            ViewerRegionName = RegionNames.BackgroundViewRegionName;
         }
 
         public async void AwaitRenderBitmap(CPDFDocument doc)
@@ -50,21 +57,56 @@ namespace PDF_Office.ViewModels.EditTools.Background
             await RenderBitmap(doc);
         }
 
-        public void SetBackground( BackgroundInfo backgroundInfo)
+        private void UndoManager_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
+        {
+        }
+
+        private WriteableBitmap GetBackground(CPDFDocument oldDoc, double zoom, int pageIndex)
+        {
+            System.Windows.Size pageSize = oldDoc.GetPageSize(pageIndex);
+
+            CPDFDocument newDoc = CPDFDocument.CreateDocument();
+            newDoc.InsertPage(0, pageSize.Width, pageSize.Height, null);
+
+          //  CreateBackground(newDoc);
+            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);
+            return WirteBitmap;
+        }
+
+        private void CurrentViewer_CustomDrawHandler(object sender, CustomDrawData e)
+        {
+            if (e.DrawPages.Count > 0 && e.DrawContext != null)
+            {
+                foreach (DrawPageData drawPageData in e.DrawPages)
+                {
+                    WriteableBitmap waterMarkBitmap = GetBackground(PDFViewer.Document, e.Zoom, drawPageData.PageIndex);
+                    e.DrawContext.DrawImage(waterMarkBitmap, drawPageData.PageBound);
+                }
+            }
+        }
+
+        public void SetBackground(BackgroundInfo backgroundInfo)
         {
-            CreateBackground(backgroundInfo);
-            document.PdfToImage("0-1", "D:\\");
-            document.WriteToFilePath("D:\\sb22222.pdf");
-            AwaitRenderBitmap(document);
+            this.BackgroundInfo = backgroundInfo;
+            CreateBackground(PDFViewer.Document);
+            AwaitRenderBitmap(Document);
         }
 
-        public void CreateBackground(BackgroundInfo backgroundInfo)
+        public void CreateBackground(CPDFDocument document)
         {
-            byte[] color = {0,255, 255};
-            background = document.GetBackground();
-            backgroundInfo.BackgroundType = C_Background_Type.BG_TYPE_IMAGE;
+            byte[] color = { 0, 255, 255 };
+            background = Document.GetBackground();
+            BackgroundInfo.BackgroundType = C_Background_Type.BG_TYPE_IMAGE;
 
-            if (backgroundInfo.BackgroundType == C_Background_Type.BG_TYPE_COLOR)
+            if (BackgroundInfo.BackgroundType == C_Background_Type.BG_TYPE_COLOR)
             {
                 background.SetBackgroundType(C_Background_Type.BG_TYPE_COLOR);
                 background.SetColor(color);
@@ -73,8 +115,8 @@ namespace PDF_Office.ViewModels.EditTools.Background
             else
             {
                 background.SetBackgroundType(C_Background_Type.BG_TYPE_IMAGE);
-                background.SetImage(backgroundInfo.ImageArray, backgroundInfo.ImageWidth, backgroundInfo.ImageHeight, ComPDFKit.Import.C_Scale_Type.fitCenter);
-                background.SetScale(1);
+                background.SetImage(BackgroundInfo.ImageArray, BackgroundInfo.ImageWidth, BackgroundInfo.ImageHeight, ComPDFKit.Import.C_Scale_Type.fitCenter);
+                background.SetScale(0.1f);
             }
             background.SetHorizalign(C_Background_Horizalign.BG_HORIZALIGN_CENTER);
             background.SetVertalign(C_Background_Vertalign.BG_VERTALIGN_CENTER);
@@ -107,7 +149,7 @@ namespace PDF_Office.ViewModels.EditTools.Background
             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.4), (int)(page.PageSize.Height * 1.4), 0, true, true);
+            Bitmap bitmap = await ToolMethod.RenderPageBitmap(Document, (int)(page.PageSize.Width * 1.4), (int)(page.PageSize.Height * 1.4), 0, true, true);
             //await Task.Run(delegate
             //{
             //    page.RenderPageBitmap(0, 0, (int)page.PageSize.Width, (int)page.PageSize.Height, 0xffffffff, bmp_data, 1);
@@ -129,9 +171,25 @@ namespace PDF_Office.ViewModels.EditTools.Background
 
         public void OnNavigatedTo(NavigationContext navigationContext)
         {
-            navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
-            document = PDFViewer.Document;
-            AwaitRenderBitmap(PDFViewer.Document);
+            CPDFViewer pdfViewer;
+
+            navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out pdfViewer);
+            if (pdfViewer != null)
+            {
+                if (!regionManager.Regions[ViewerRegionName].Views.Contains(PDFViewer))
+                {
+                    PDFViewer = new CPDFViewer();
+                    PDFViewer.InitDocument(pdfViewer.Document.FilePath);
+                    Document = PDFViewer.Document;
+                    PDFViewer.CustomDrawHandler += CurrentViewer_CustomDrawHandler;
+                    PDFViewer.UndoManager.PropertyChanged += UndoManager_PropertyChanged;
+                    regionManager.AddToRegion(ViewerRegionName, PDFViewer);
+                    PDFViewer.SetAnnotInteraction(!PDFViewer.GetAnnotInteraction());
+                    PDFViewer.Load();
+                    PDFViewer.ChangeViewMode(ViewMode.Single);
+                    PDFViewer.SetMouseMode(MouseModes.Default);
+                }
+            }
         }
     }
 }

+ 2 - 19
PDF Office/ViewModels/EditTools/Background/BackgroundTemplateListColorContentViewModel.cs

@@ -74,9 +74,7 @@ namespace PDF_Office.ViewModels.EditTools.Background
             }
             BackgroundModColorCollection = new ObservableCollection<BackgroundItem>(backgroundModColorTemplateList);
             CheckTemplateListIsEmpty(backgroundModColorTemplateList);
-        }
-
-
+        } 
 
         private void InitBackgroundTemplateList()
         {
@@ -87,20 +85,6 @@ namespace PDF_Office.ViewModels.EditTools.Background
             GetBackgroundSource();
         }
 
-        private void UpdateBackgroundSources()
-        {
-            List<BackgroundItem> backgroundModColorTemplateList = new List<BackgroundItem>();
-            for (int temp = 0; temp < Settings.Default.BackgroundTemplateList.Count; temp++)
-            {
-                if (Settings.Default.BackgroundTemplateList[temp].type == ComPDFKit.PDFDocument.C_Background_Type.BG_TYPE_COLOR)
-                {
-                    backgroundModColorTemplateList.Add(Settings.Default.BackgroundTemplateList[temp]);
-                }
-            }
-            BackgroundModColorCollection = new ObservableCollection<BackgroundItem>(backgroundModColorTemplateList);
-            CheckTemplateListIsEmpty(backgroundModColorTemplateList);
-        }
-
         public void AddTemplate()
         {
             this.eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Publish(EnumTemplateListOrCreate.StatusCreate);
@@ -125,7 +109,7 @@ namespace PDF_Office.ViewModels.EditTools.Background
             Settings.Default.Save();
 
             BackgroundModColorCollection.Remove(template);
-            UpdateBackgroundSources();
+            GetBackgroundSource();
 
         }
 
@@ -141,7 +125,6 @@ namespace PDF_Office.ViewModels.EditTools.Background
         public void OnNavigatedTo(NavigationContext navigationContext)
         {
             InitBackgroundTemplateList();
-
         }
     }
 }

+ 43 - 29
PDF Office/ViewModels/EditTools/Background/BackgroundTemplateListFileContentViewModel.cs

@@ -1,6 +1,8 @@
-using PDF_Office.Properties;
+using PDF_Office.EventAggregators;
+using PDF_Office.Properties;
 using PDFSettings;
 using Prism.Commands;
+using Prism.Events;
 using Prism.Mvvm;
 using Prism.Regions;
 using System;
@@ -10,11 +12,15 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using System.Windows;
+using System.Windows.Controls;
 
 namespace PDF_Office.ViewModels.EditTools.Background
 {
     public class BackgroundTemplateListFileContentViewModel : BindableBase,INavigationAware
     {
+        private readonly IEventAggregator eventAggregator;
+
+
         public ObservableCollection<BackgroundItem> backgroundModFileCollection = new ObservableCollection<BackgroundItem>();
         public ObservableCollection<BackgroundItem> BackgroundModFileCollection
         {
@@ -35,13 +41,16 @@ namespace PDF_Office.ViewModels.EditTools.Background
 
         public DelegateCommand AddTemplateCommand { get; set; }
         public DelegateCommand<object> DeleteTemplateItemCommand { get; set; }
+        public DelegateCommand DeleteAllTemplateItemCommand{ get; set; }
+        public DelegateCommand<object> SelectTemplateItemCommand { get; set; }
 
-        BackgroundTemplateListFileContentViewModel()
+        BackgroundTemplateListFileContentViewModel(IEventAggregator eventAggregator)
         {
+            this.eventAggregator = eventAggregator;
             AddTemplateCommand = new DelegateCommand(AddTemplate);
             DeleteTemplateItemCommand = new DelegateCommand<object>(DeleteTemplateItem);
-
-            InitBackgroundTemplateList();
+            DeleteAllTemplateItemCommand = new DelegateCommand(DeleteAllTemplateItem);
+            SelectTemplateItemCommand = new DelegateCommand<object>(SelectTemplateItem);
         }
 
         private void CheckTemplateListIsEmpty(List<BackgroundItem> backgroundTemplateList)
@@ -81,40 +90,21 @@ namespace PDF_Office.ViewModels.EditTools.Background
             GetBackgroundSource();
         }
 
-        private void UpdateBackgroundSources()
-        {
-            int count = backgroundModFileCollection.Count + backgroundModFileCollection.Count;
-            List<BackgroundItem> backgroundModFileTemplateList = new List<BackgroundItem>();
-            for (int temp = 0; temp < Settings.Default.BackgroundTemplateList.Count; temp++)
-            {
-                if (Settings.Default.BackgroundTemplateList[temp].type == ComPDFKit.PDFDocument.C_Background_Type.BG_TYPE_IMAGE)
-                {
-                    backgroundModFileTemplateList.Add(Settings.Default.BackgroundTemplateList[temp]);
-                }
-            }
-            BackgroundModFileCollection = new ObservableCollection<BackgroundItem>(backgroundModFileTemplateList);
-            CheckTemplateListIsEmpty(backgroundModFileTemplateList);
-        }
 
         public void AddTemplate()
         {
-            var backgroundItem = new BackgroundItem();
-            backgroundItem.pageRange = "0";
-            backgroundItem.type = ComPDFKit.PDFDocument.C_Background_Type.BG_TYPE_IMAGE;
-            backgroundItem.templateName += Settings.Default.BackgroundIndex.ToString();
-            Settings.Default.BackgroundTemplateList.Add(backgroundItem);
-            Settings.Default.Save();
-            UpdateBackgroundSources();
+            this.eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Publish(EnumTemplateListOrCreate.StatusCreate);
+
         }
 
         public void DeleteTemplateItem(object e)
         {
-            var btn = e as System.Windows.Controls.Button;
-            if (btn == null)
+            var control = e as  Control;
+            if (control == null)
             {
                 return;
             }
-            var template = btn.DataContext as BackgroundItem;
+            var template = control.DataContext as BackgroundItem;
             if (template == null)
             {
                 return;
@@ -126,10 +116,33 @@ namespace PDF_Office.ViewModels.EditTools.Background
             Settings.Default.Save();
 
             BackgroundModFileCollection.Remove(template);
-            UpdateBackgroundSources();
+            GetBackgroundSource();
 
         }
 
+        public void DeleteAllTemplateItem()
+        { 
+                while (Settings.Default.BackgroundTemplateList.Count != 0)
+                {
+                    int temp = 0;
+                    var template = Settings.Default.BackgroundTemplateList[temp];
+                    Settings.Default.AppProperties.NeedToDeletePath.Add(template.previeImagePath);
+                    Settings.Default.AppProperties.NeedToDeletePath.Add(template.imagepath);
+
+                    Settings.Default.BackgroundTemplateList.Remove(template);
+                    Settings.Default.Save();
+
+                    BackgroundModFileCollection.Remove(template);
+                }
+            GetBackgroundSource();
+        }
+
+        public void SelectTemplateItem(object e)
+        {
+            var listBox = e as  ListBox;
+          var xxx =   listBox.SelectedItem as BackgroundItem;
+        }
+
         public bool IsNavigationTarget(NavigationContext navigationContext)
         {
             return true;
@@ -141,6 +154,7 @@ namespace PDF_Office.ViewModels.EditTools.Background
 
         public void OnNavigatedTo(NavigationContext navigationContext)
         {
+            InitBackgroundTemplateList();
         }
     }
 }

+ 13 - 10
PDF Office/Views/EditTools/Background/BackgroundTemplateListColorContent.xaml

@@ -27,24 +27,27 @@
                     <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>
                 <DataTemplate DataType="{x:Type data:BackgroundItem}">
-                    <StackPanel Name="itemPanel" >
-                        <Grid Height="160" Width=" 128" Background="Blue">
-                            <Label  Height="160" Width=" 128"></Label>
-                            <Label  Height="160" Width=" 128"></Label>
-                            <Button Name="EditTemplateBtn" Height="43" Width="63" HorizontalAlignment="Left" VerticalAlignment="Bottom"></Button>
-                            <Button Name="DeleteTemplateBtn"  Height="43" Width="63" HorizontalAlignment="Right" VerticalAlignment="Bottom" Click="DeleteTemplateBtn_Click"  Command="{Binding DeleteTemplateItemCommand}" CommandParameter="{Binding ElementName=DeleteTemplateBtn}">
-                            </Button>
-                        </Grid>
+                    <StackPanel Name="itemPanel"  Height="160" Width=" 128" >
+                        <Border BorderThickness="1" BorderBrush="#A0A2AE">
+                            <Grid Height="160" Width=" 128" Background="LightBlue">
+                                <Label  Height="160" Width=" 128"></Label>
+                                <Label  Height="160" Width=" 128"></Label>
+                                <Button Name="EditTemplateBtn" Height="43" Width="63" HorizontalAlignment="Left" VerticalAlignment="Bottom"></Button>
+                                <Button Name="DeleteTemplateBtn"  Height="43" Width="63" HorizontalAlignment="Right" VerticalAlignment="Bottom" Click="DeleteTemplateBtn_Click" >
+                                </Button>
+                            </Grid>
+                        </Border>
                     </StackPanel>
                     <DataTemplate.Triggers>
                         <Trigger Property="IsMouseOver" Value="True">
                             <Setter TargetName="EditTemplateBtn" Property="Visibility" Value="Visible"/>
                             <Setter TargetName="DeleteTemplateBtn" Property="Visibility" Value="Visible"/>
+
                         </Trigger>
                         <Trigger Property="IsMouseOver" Value="False">
                             <Setter TargetName="EditTemplateBtn" Property="Visibility" Value="Collapsed"/>
@@ -54,7 +57,7 @@
                 </DataTemplate>
             </ListBox.ItemTemplate>
         </ListBox>
-        <Grid Height="155" Margin="64,153,56,324" Visibility="{Binding CreateTemplateVisible, Mode=OneWay}">
+        <Grid Margin="64,153,56,0" Visibility="{Binding CreateTemplateVisible, Mode=OneWay}">
             <StackPanel Orientation="Vertical">
                 <Label Height="87" Width="87" HorizontalAlignment="Center" Background="BlueViolet"></Label>
                 <TextBlock Height="24" FontSize="14" Text="请先创建一个背景模板" Margin="0,8,0,0" VerticalAlignment="Center" ></TextBlock>

+ 31 - 12
PDF Office/Views/EditTools/Background/BackgroundTemplateListFileContent.xaml

@@ -9,8 +9,24 @@
              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" 
+        <ListBox
                                 Width="240" 
                                 BorderThickness="0"
                                 ScrollViewer.CanContentScroll="True"
@@ -22,23 +38,26 @@
                                 VirtualizingPanel.CacheLength="1"
                                 VirtualizingPanel.ScrollUnit="Pixel"   
                                 Background="#F3F3F3"
-                 ItemsSource="{Binding BackgroundModFileCollection}">
+                 ItemsSource="{Binding BackgroundModFileCollection}"  
+            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="Margin" Value="20"/>
+                    <Setter Property="Padding" Value="0 0 0 0"/>
+                    <Setter Property="Height" Value="160"/>
+                    <Setter Property="Width" Value="128"/>
+                    <Setter Property="ContextMenu" Value="{StaticResource FlyoutMenu}"/>
+                    <Setter Property="Template" Value="{DynamicResource EditToolsItemControlTemplate}"/>
                 </Style>
             </ListBox.ItemContainerStyle>
             <ListBox.ItemTemplate>
                 <DataTemplate DataType="{x:Type data:BackgroundItem}">
-                    <StackPanel Name="itemPanel" >
-                        <Grid Height="160" Width=" 128" Background="Blue">
-                            <Label  Height="160" Width=" 128"></Label>
+                    <StackPanel Name="itemPanel">
+                        <Grid Height="160" Width=" 128" Background="LightBlue">
                             <Label  Height="160" Width=" 128"></Label>
-                            <Button Name="EditTemplateBtn" Height="43" Width="63" HorizontalAlignment="Left" VerticalAlignment="Bottom"></Button>
-                            <Button Name="DeleteTemplateBtn"  Height="43" Width="63" HorizontalAlignment="Right" VerticalAlignment="Bottom" Click="DeleteTemplateBtn_Click"  Command="{Binding DeleteTemplateItemCommand}" CommandParameter="{Binding ElementName=DeleteTemplateBtn}">
+                              <Button Name="EditTemplateBtn" Height="43" Width="63" HorizontalAlignment="Left" VerticalAlignment="Bottom"></Button>
+                            <Button Name="DeleteTemplateBtn"  Height="43" Width="63" HorizontalAlignment="Right" VerticalAlignment="Bottom" Click="DeleteTemplateBtn_Click">
                             </Button>
                         </Grid>
                     </StackPanel>
@@ -55,7 +74,7 @@
                 </DataTemplate>
             </ListBox.ItemTemplate>
         </ListBox>
-        <Grid Width="140" Height="155" Margin="64,153,56,323" Visibility="{Binding CreateTemplateVisible, Mode=OneWay}">
+        <Grid Width="140"  Margin="64,153,56,0" Visibility="{Binding CreateTemplateVisible, Mode=OneWay}">
             <StackPanel Orientation="Vertical">
                 <Label Height="87" Width="87" HorizontalAlignment="Center" Background="BlueViolet"></Label>
                 <TextBlock Height="24" FontSize="14" Text="请先创建一个背景模板" Margin="0,8,0,0" VerticalAlignment="Center" ></TextBlock>

+ 23 - 0
PDF Office/Views/EditTools/Background/BackgroundTemplateListFileContent.xaml.cs

@@ -1,4 +1,5 @@
 using PDF_Office.ViewModels.EditTools.Background;
+using System.Windows;
 using System.Windows.Controls;
 
 namespace PDF_Office.Views.EditTools.Background
@@ -20,5 +21,27 @@ namespace PDF_Office.Views.EditTools.Background
         {
             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();
+        }
     }
 }

+ 3 - 3
PDF Office/Views/EditTools/Watermark/WatermarkDocumentContent.xaml

@@ -9,9 +9,9 @@
              d:DesignHeight="720"
              d:DesignWidth="1020" >
     <Grid Height="720" Width="1020" Background="SkyBlue">
-        <ContentControl
-                x:Name="PDFViewerContent"
-                HorizontalAlignment="Stretch"
+        <ContentControl
+                x:Name="PDFViewerContent"
+                HorizontalAlignment="Stretch"
                 prism:RegionManager.RegionName="{Binding ViewerRegionName}" />
         <Border  Height="64" Width="293" HorizontalAlignment="Center"  VerticalAlignment="Bottom"  Panel.ZIndex="1" Margin="9" Background="#323232" CornerRadius="4">
             <Grid>