Browse Source

水印-属性设置

liyijie 2 years ago
parent
commit
1a159fe19b

+ 1 - 0
PDF Office/App.xaml.cs

@@ -133,6 +133,7 @@ namespace PDF_Office
             containerRegistry.RegisterForNavigation<WatermarkCreateBaseContent>();
             containerRegistry.RegisterForNavigation<WatermarkCreateTextContent>();
             containerRegistry.RegisterForNavigation<WatermarkCreateFileContent>();
+            containerRegistry.RegisterForNavigation<WatermarkDocumentContent>();
 
             //注册弹窗
             containerRegistry.RegisterDialog<VerifyPassWordDialog>(DialogNames.VerifyPassWordDialog);

+ 15 - 0
PDF Office/EventAggregators/EditToolsEvent.cs

@@ -1,4 +1,5 @@
 using PDF_Office.Model.EditTools.Background;
+using PDF_Office.Model.EditTools.Watermark;
 using Prism.Events;
 using System;
 using System.Collections.Generic;
@@ -23,6 +24,13 @@ namespace PDF_Office.EventAggregators
         StatusFile
     }
 
+    public enum EnumTextOrFile
+    {
+        StatusNone = -1,
+        StatusText,
+        StatusFile
+    }
+
     public class EnterSelectedEditToolEvent : PubSubEvent<string>
     {
     }
@@ -37,6 +45,10 @@ namespace PDF_Office.EventAggregators
 
     public class ConfirmEditToolsEvent : PubSubEvent<EnumColorOrFile>
     {
+    }
+
+    public class ConfirmEditToolsWatermarkEvent : PubSubEvent<EnumTextOrFile>
+    {
     }
 
     public class SetCurrentCreateModEvent : PubSubEvent<string>
@@ -45,5 +57,8 @@ namespace PDF_Office.EventAggregators
 
     public class SetBackgroundEvent : PubSubEvent<BackgroundInfo>
     {
+    }
+    public class SetWatermarkEvent : PubSubEvent<WatermarkInfo>
+    {
     }
 }

+ 8 - 0
PDF Office/PDF Office.csproj

@@ -356,6 +356,7 @@
     <Compile Include="ViewModels\EditTools\Watermark\WatermarkTemplateListBaseContentViewModel.cs" />
     <Compile Include="ViewModels\EditTools\Watermark\WatermarkTemplateListFileContentViewModel.cs" />
     <Compile Include="ViewModels\EditTools\Watermark\WatermarkTemplateListTextContentViewModel.cs" />
+    <Compile Include="ViewModels\EditTools\Watermark\WatermarkDocumentContentViewModel.cs" />
     <Compile Include="Views\BOTA\BOTAContent.xaml.cs">
       <DependentUpon>BOTAContent.xaml</DependentUpon>
     </Compile>
@@ -491,6 +492,9 @@
     <Compile Include="Views\EditTools\Watermark\WatermarkCreateTextContent.xaml.cs">
       <DependentUpon>WatermarkCreateTextContent.xaml</DependentUpon>
     </Compile>
+    <Compile Include="Views\EditTools\Watermark\WatermarkDocumentContent.xaml.cs">
+      <DependentUpon>WatermarkDocumentContent.xaml</DependentUpon>
+    </Compile>
     <Compile Include="Views\EditTools\Watermark\WatermarkTemplateListBaseContent.xaml.cs">
       <DependentUpon>WatermarkTemplateListBaseContent.xaml</DependentUpon>
     </Compile>
@@ -829,6 +833,10 @@
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
     </Page>
+    <Page Include="Views\EditTools\Watermark\WatermarkDocumentContent.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
     <Page Include="Views\EditTools\Watermark\WatermarkTemplateListBaseContent.xaml">
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>

+ 3 - 3
PDF Office/ViewModels/EditTools/Background/BackgroundCreateBaseContentViewModel.cs

@@ -28,11 +28,11 @@ namespace PDF_Office.ViewModels.EditTools.Background
             set => SetProperty(ref backgroundCreateRegionName, value);
         }
 
-        private string _currentCreateName;
+        private string _currentCreateModName;
         public string CurrentCreateModName
         {
-            get => _currentCreateName;
-            set=>_currentCreateName= value;
+            get => _currentCreateModName;
+            set=>_currentCreateModName= value;
         }
 
 

+ 68 - 5
PDF Office/ViewModels/EditTools/Watermark/WatermarkContentViewModel.cs

@@ -1,4 +1,6 @@
-using PDF_Office.EventAggregators;
+using ComPDFKitViewer.PdfViewer;
+using PDF_Office.EventAggregators;
+using PDF_Office.Model;
 using Prism.Commands;
 using Prism.Events;
 using Prism.Mvvm;
@@ -13,10 +15,14 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
     public class WatermarkContentViewModel : BindableBase,INavigationAware
     {
         public IEventAggregator eventAggregator;
-        public IRegionManager backgroundRegion;
+        public IRegionManager watermarkRegion;
 
         public string TemplateListName = "WatermarkTemplateListBaseContent";
         public string CreateName = "WatermarkCreateBaseContent";
+        public string CreateModTextName = "WatermarkCreateTextContent";
+        public string CreateModFileName = "WatermarkCreateFileContent";
+
+        public string WatermarkDocumentName = "WatermarkDocumentContent";
 
         private string _watermarkSettingsRegionName;
         public string WatermarkSettingsRegionName
@@ -32,21 +38,53 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
             set { _watermarkSettingsVisible = value; }
         }
 
+        private string _watermarkDocumentRegionName;
+        /// <summary>
+        /// 持有Document的Region,负责渲染和保存
+        /// </summary>
+        public string WatermarkDocumentRegionName
+        {
+            get { return _watermarkDocumentRegionName; }
+            set { _watermarkDocumentRegionName = value; }
+        }
+
+        private Visibility _watermarkDocumentVisible = Visibility.Visible;
+        /// <summary>
+        /// 持有Document的Region可见
+        /// </summary>
+        public Visibility WatermarkDocumentVisible
+        {
+            get { return _watermarkDocumentVisible; }
+            set { _watermarkDocumentVisible = value; }
+        }
+
+        private EnumTextOrFile _currentCreateMod;
+        public EnumTextOrFile CurrentCreateMod
+        {
+            get { return _currentCreateMod; }
+            set { _currentCreateMod = value; }
+        }
 
         public DelegateCommand CloseEditToolCommand { get; set; }
 
+        public DelegateCommand ConfirmEditToolCommand { get; set; }
+
         public DelegateCommand<string> EnterSelectedContentCommand { get; set; }
+
         public WatermarkContentViewModel(IRegionManager regionManager, IEventAggregator eventAggregator)
         {
             this.eventAggregator = eventAggregator;
-            this.backgroundRegion = regionManager;
+            this.watermarkRegion = regionManager;
             WatermarkSettingsVisible = Visibility.Visible;
             WatermarkSettingsRegionName = Guid.NewGuid().ToString();
-
+            WatermarkDocumentRegionName = Guid.NewGuid().ToString();
             CloseEditToolCommand = new DelegateCommand(CloseEditTool);
+            ConfirmEditToolCommand = new DelegateCommand(ConfirmEditTool);
             EnterSelectedContentCommand = new DelegateCommand<string>(EnterSelectedContent);
 
             eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Subscribe(EnterTemplateListOrCreate);
+            eventAggregator.GetEvent<SetCurrentCreateModEvent>().Subscribe(SetCurrentCreateMod);
+
         }
         public void CloseEditTool()
         {
@@ -54,6 +92,11 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
 
         }
 
+        public void ConfirmEditTool()
+        {
+            this.eventAggregator.GetEvent<ConfirmEditToolsWatermarkEvent>().Publish(CurrentCreateMod);
+        }
+
         public void EnterTemplateListOrCreate(EnumTemplateListOrCreate enumTemplateListOrCreate)
         {
             if (enumTemplateListOrCreate == EnumTemplateListOrCreate.StatusTemplate)
@@ -66,15 +109,35 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
             }
         }
 
+        public void SetCurrentCreateMod(string currentCreateModName)
+        {
+            if (currentCreateModName == CreateModTextName)
+            {
+                CurrentCreateMod = EnumTextOrFile.StatusText;
+            }
+            else if (currentCreateModName == CreateModFileName)
+            {
+                CurrentCreateMod = EnumTextOrFile.StatusFile;
+            }
+        }
+
         public void EnterSelectedContent(string SelectedContentName)
         {
-            backgroundRegion.RequestNavigate(WatermarkSettingsRegionName, SelectedContentName);
+            watermarkRegion.RequestNavigate(WatermarkSettingsRegionName, SelectedContentName);
             WatermarkSettingsVisible = Visibility.Visible;
         }
 
+        public void EnterDocumentContent()
+        {
+            watermarkRegion.RequestNavigate(WatermarkDocumentRegionName, WatermarkDocumentName);
+            WatermarkDocumentVisible = Visibility.Visible;
+        }
+
         public void OnNavigatedTo(NavigationContext navigationContext)
         {
             EnterSelectedContent(TemplateListName);
+            EnterDocumentContent();
+
         }
 
         public bool IsNavigationTarget(NavigationContext navigationContext)

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

@@ -31,6 +31,13 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
             set => _currentCreateName = value;
         }
 
+        private string _currentCreateModName;
+        public string CurrentCreateModName
+        {
+            get => _currentCreateModName;
+            set => _currentCreateModName = value;
+        }
+
 
         private System.Windows.Visibility watermarkCreateVisible;
         public System.Windows.Visibility WatermarkCreateVisible
@@ -69,6 +76,8 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
             {
                 CurrentCreateName = args.Name;
                 EnterSelectedCreateMod(CurrentCreateName);
+                eventAggregator.GetEvent<SetCurrentCreateModEvent>().Publish(CurrentCreateName);
+
             }
         }
 

+ 15 - 1
PDF Office/ViewModels/EditTools/Watermark/WatermarkCreateTextContentViewModel.cs

@@ -1,10 +1,12 @@
 using ComPDFKit.PDFDocument;
 using ComPDFKit.PDFWatermark;
 using ComPDFKitViewer.PdfViewer;
+using PDF_Office.EventAggregators;
 using PDF_Office.Helper;
 using PDF_Office.Model.EditTools.Background;
 using PDF_Office.Model.EditTools.Watermark;
 using Prism.Commands;
+using Prism.Events;
 using Prism.Mvvm;
 using Prism.Regions;
 using System;
@@ -17,6 +19,8 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
     {
         public WatermarkInfo WatermarkInfo = new WatermarkInfo();
 
+        IEventAggregator eventAggregator;
+
         public CPDFViewer currentViewer;
 
         private List<string> _opacityList = new List<string>();
@@ -285,13 +289,15 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
 
         public DelegateCommand<object> ChangeLocationCommand { get; set; }
 
-        public WatermarkCreateTextContentViewModel()
+        public WatermarkCreateTextContentViewModel(IEventAggregator eventAggregator)
         {
+            this.eventAggregator=eventAggregator;
             ChangeLocationCommand = new DelegateCommand<object>(ChangeLocation);
             InitList();
             WatermarkInfo.WatermarkHorizalign = C_Watermark_Horizalign.WATERMARK_HORIZALIGN_CENTER;
             WatermarkInfo.WatermarkVertalign = C_Watermark_Vertalign.WATERMARK_VERTALIGN_CENTER;
             InitLocationButtonMatrix();
+            eventAggregator.GetEvent<ConfirmEditToolsWatermarkEvent>().Subscribe(ConfirmEditToolsWatermark);
         }
 
         private void InitLocationButtonMatrix()
@@ -349,6 +355,14 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
             }
         }
 
+        public void ConfirmEditToolsWatermark(EnumTextOrFile enumTextOrFile)
+        {
+            if (enumTextOrFile == EnumTextOrFile.StatusText)
+            {
+                eventAggregator.GetEvent<SetWatermarkEvent>().Publish(WatermarkInfo);
+            }
+        }
+
         private void InitList() {
             InitOpacityList();
             InitFontNameList();

+ 46 - 0
PDF Office/ViewModels/EditTools/Watermark/WatermarkDocumentContentViewModel.cs

@@ -0,0 +1,46 @@
+using ComPDFKitViewer.PdfViewer;
+using PDF_Office.EventAggregators;
+using PDF_Office.Model.EditTools.Background;
+using PDF_Office.Model;
+using Prism.Commands;
+using Prism.Events;
+using Prism.Mvvm;
+using Prism.Regions;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using PDF_Office.Model.EditTools.Watermark;
+
+namespace PDF_Office.ViewModels.EditTools.Watermark
+{
+    public class WatermarkDocumentContentViewModel : BindableBase
+    {
+
+        public IEventAggregator eventAggregator;
+        public CPDFViewer PDFViewer;
+        public WatermarkDocumentContentViewModel(IEventAggregator eventAggregator)
+        {
+            this.eventAggregator = eventAggregator;
+            eventAggregator.GetEvent<SetWatermarkEvent>().Subscribe(SetWatermark);
+        }
+
+        public void SetWatermark(WatermarkInfo watermarkInfo)
+        {
+
+        }
+
+        public bool IsNavigationTarget(NavigationContext navigationContext)
+        {
+            return true;
+        }
+
+        public void OnNavigatedFrom(NavigationContext navigationContext)
+        {
+        }
+
+        public void OnNavigatedTo(NavigationContext navigationContext)
+        {
+            navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
+        }
+    }
+}

+ 3 - 24
PDF Office/Views/EditTools/Watermark/WatermarkContent.xaml

@@ -3,7 +3,7 @@
              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
              xmlns:prism="http://prismlibrary.com/"             
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
-             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:background="clr-namespace:PDF_Office.ViewModels.EditTools.Background" d:DataContext="{d:DesignInstance Type=background:BackgroundContentViewModel}"
+             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:watermark="clr-namespace:PDF_Office.ViewModels.EditTools.Watermark" d:DataContext="{d:DesignInstance Type=watermark:WatermarkContentViewModel}"
              mc:Ignorable="d"
              prism:ViewModelLocator.AutoWireViewModel="True"
              d:DesignHeight="760"
@@ -55,7 +55,7 @@
                 </WrapPanel>
             </Border>
             <StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
-                <Button Content="应用" Height="24" Width="44" ></Button>
+                <Button Content="应用" Height="24" Width="44" Command="{Binding ConfirmEditToolCommand}"></Button>
                 <Button Content="关闭" Height="24" Width="44" Margin="16,0,16,0" Command="{Binding CloseEditToolCommand}"></Button>
             </StackPanel>
         </Grid>
@@ -65,28 +65,7 @@
                 <ColumnDefinition Width="260"></ColumnDefinition>
             </Grid.ColumnDefinitions>
             <Grid Grid.Column="0" Background="#E7E9EC" >
-                <Border  Height="64" Width="293" HorizontalAlignment="Center"  VerticalAlignment="Bottom"  Panel.ZIndex="1" Margin="9" Background="#323232" CornerRadius="4">
-
-                    <Grid>
-                        <StackPanel Orientation="Horizontal"  VerticalAlignment="Center">
-                            <StackPanel Orientation="Horizontal">
-
-                                <TextBlock Text="-" FontSize="20" Foreground="White" Margin="20,0,20,0"></TextBlock>
-                                <TextBlock Text="+" FontSize="20" Foreground="White" Margin="0,0,39,0"></TextBlock>
-                            </StackPanel>
-                            <StackPanel Orientation="Horizontal">
-                                <TextBlock Text="1" FontSize="20" Foreground="White" Margin="0,0,24,0"></TextBlock>
-                                <TextBlock Text="/" FontSize="20" Foreground="White" Margin="0,0,24,0"></TextBlock>
-                                <TextBlock Text="20" FontSize="20" Foreground="White" Margin="0,0,24,0"></TextBlock>
-                            </StackPanel>
-                            <StackPanel Orientation="Horizontal">
-                                <TextBlock Text="↑" FontSize="20" Foreground="White" Margin="20,0,20,0"></TextBlock>
-                                <TextBlock Text="↓" FontSize="20" Foreground="White"></TextBlock>
-
-                            </StackPanel>
-                        </StackPanel>
-                    </Grid>
-                </Border>
+                <ContentControl prism:RegionManager.RegionName="{Binding WatermarkDocumentRegionName}" Visibility="{Binding WatermarkDocumentVisible}"></ContentControl>
             </Grid>
             <Grid Grid.Column="1" Background="#F3F3F3">
                 <ContentControl prism:RegionManager.RegionName="{Binding WatermarkSettingsRegionName}" Visibility="{Binding WatermarkSettingsVisible}"></ContentControl>

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

@@ -4,7 +4,7 @@
              xmlns:prism="http://prismlibrary.com/"             
              prism:ViewModelLocator.AutoWireViewModel="True"
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
-             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
+             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:watermark="clr-namespace:PDF_Office.ViewModels.EditTools.Watermark" d:DataContext="{d:DesignInstance Type=watermark:WatermarkCreateBaseContentViewModel}"
              mc:Ignorable="d"
              d:DesignHeight="720"
              d:DesignWidth="260" >

+ 10 - 10
PDF Office/Views/EditTools/Watermark/WatermarkCreateTextContent.xaml

@@ -29,16 +29,16 @@
                         <Button Width="34.67" Height="32"></Button>
                         <Button Width="34.67" Height="32"></Button>
                     </StackPanel>
-                    <Button Height="32" Width="66"  Margin="8,0,0,0">
-                        <Grid Height="32" Width="66" HorizontalAlignment="Center" VerticalAlignment="Center">
-                            <Grid.ColumnDefinitions>
-                                <ColumnDefinition></ColumnDefinition>
-                                <ColumnDefinition></ColumnDefinition>
-                            </Grid.ColumnDefinitions>
-                            <Grid Grid.Column="0" Height="22" Width="22">
-                                <Rectangle Fill="{Binding StringColor, Mode=TwoWay}" RadiusX="20" RadiusY="20"></Rectangle>
-                            </Grid>
-                        </Grid>
+                    <Button Height="32" Width="66"  Margin="8,0,0,0">
+                        <Grid Height="32" Width="66" HorizontalAlignment="Center" VerticalAlignment="Center">
+                            <Grid.ColumnDefinitions>
+                                <ColumnDefinition></ColumnDefinition>
+                                <ColumnDefinition></ColumnDefinition>
+                            </Grid.ColumnDefinitions>
+                            <Grid Grid.Column="0" Height="22" Width="22">
+                                <Rectangle Fill="{Binding StringColor, Mode=TwoWay}" RadiusX="20" RadiusY="20"></Rectangle>
+                            </Grid>
+                        </Grid>
                     </Button>
                 </StackPanel>
             </StackPanel>

+ 33 - 0
PDF Office/Views/EditTools/Watermark/WatermarkDocumentContent.xaml

@@ -0,0 +1,33 @@
+<UserControl x:Class="PDF_Office.Views.EditTools.Watermark.WatermarkDocumentContent"
+             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+             xmlns:prism="http://prismlibrary.com/"             
+             prism:ViewModelLocator.AutoWireViewModel="True"
+             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+              mc:Ignorable="d"
+             d:DesignHeight="720"
+             d:DesignWidth="1020" >
+    <Grid Height="720" Width="1020" Background="SkyBlue">
+        <Border  Height="64" Width="293" HorizontalAlignment="Center"  VerticalAlignment="Bottom"  Panel.ZIndex="1" Margin="9" Background="#323232" CornerRadius="4">
+            <Grid>
+                <StackPanel Orientation="Horizontal"  VerticalAlignment="Center">
+                    <StackPanel Orientation="Horizontal">
+                        <TextBlock Text="-" FontSize="20" Foreground="White" Margin="20,0,20,0"></TextBlock>
+                        <TextBlock Text="+" FontSize="20" Foreground="White" Margin="0,0,39,0"></TextBlock>
+                    </StackPanel>
+                    <StackPanel Orientation="Horizontal">
+                        <TextBlock Text="1" FontSize="20" Foreground="White" Margin="0,0,24,0"></TextBlock>
+                        <TextBlock Text="/" FontSize="20" Foreground="White" Margin="0,0,24,0"></TextBlock>
+                        <TextBlock Text="20" FontSize="20" Foreground="White" Margin="0,0,24,0"></TextBlock>
+                    </StackPanel>
+                    <StackPanel Orientation="Horizontal">
+                        <TextBlock Text="↑" FontSize="20" Foreground="White" Margin="20,0,20,0"></TextBlock>
+                        <TextBlock Text="↓" FontSize="20" Foreground="White"></TextBlock>
+
+                    </StackPanel>
+                </StackPanel>
+            </Grid>
+        </Border>
+    </Grid>
+</UserControl>

+ 15 - 0
PDF Office/Views/EditTools/Watermark/WatermarkDocumentContent.xaml.cs

@@ -0,0 +1,15 @@
+using System.Windows.Controls;
+
+namespace PDF_Office.Views.EditTools.Watermark
+{
+    /// <summary>
+    /// Interaction logic for WatermarkDocumentContent
+    /// </summary>
+    public partial class WatermarkDocumentContent : UserControl
+    {
+        public WatermarkDocumentContent()
+        {
+            InitializeComponent();
+        }
+    }
+}