Explorar el Código

弹窗-补充文档解密弹窗

ZhouJieSheng hace 2 años
padre
commit
a3a9eafd27

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

@@ -13,6 +13,7 @@ using PDF_Office.CustomControl;
 using PDF_Office.ViewModels;
 using PDF_Office.Views;
 using PDF_Office.Views.BOTA;
+using PDF_Office.Views.Dialog;
 using PDF_Office.Views.HomePanel;
 using Prism.DryIoc;
 using Prism.Ioc;
@@ -59,7 +60,7 @@ namespace PDF_Office
 
         protected override void RegisterTypes(IContainerRegistry containerRegistry)
         {
-            //单例
+            //注册内容组件
             containerRegistry.RegisterForNavigation<HomeContent>();
             containerRegistry.RegisterForNavigation<ViewContent>();
             containerRegistry.RegisterForNavigation<MainContent>();
@@ -67,6 +68,9 @@ namespace PDF_Office
             containerRegistry.RegisterForNavigation<HomeToolsContent>("Tools");
             containerRegistry.RegisterForNavigation<HomeGuidContent>("Guid");
             containerRegistry.RegisterForNavigation<BOTAContent>();
+
+            //注册弹窗
+            containerRegistry.RegisterDialog<VerifyPassWordDialog>(DialogNames.VerifyPassWordDialog);
         }
 
         protected override void ConfigureRegionAdapterMappings(RegionAdapterMappings regionAdapterMappings)

+ 13 - 0
PDF Office/CustomControl/DialogNames.cs

@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace PDF_Office.CustomControl
+{
+    public static class DialogNames
+    {
+        public static string VerifyPassWordDialog = "PassWordDialog";
+    }
+}

+ 2 - 0
PDF Office/PDF Office.csproj

@@ -102,6 +102,7 @@
       <Generator>MSBuild:Compile</Generator>
       <SubType>Designer</SubType>
     </ApplicationDefinition>
+    <Compile Include="CustomControl\DialogNames.cs" />
     <Compile Include="CustomControl\InterTabClient.cs" />
     <Compile Include="CustomControl\LoadingControl.xaml.cs">
       <DependentUpon>LoadingControl.xaml</DependentUpon>
@@ -265,6 +266,7 @@
     <Content Include="Dragablz.dll">
       <CopyToOutputDirectory>Always</CopyToOutputDirectory>
     </Content>
+    <Resource Include="StyleAndTemplateList.txt" />
     <Content Include="SystemService\PreviewHandler.dll">
       <CopyToOutputDirectory>Always</CopyToOutputDirectory>
     </Content>

+ 7 - 1
PDF Office/StyleAndTemplateList.txt

@@ -1,2 +1,8 @@
 用于记录已添加的自定义样式和自定义控件模板,防止重复造轮子。
-每条记录至少包含以下信息:名称、用途(仅用于某个具体功能or莫类型功能通用)、使用方法、效果、备注(有哪些要注意的地方)
+每条记录至少包含以下信息:名称、用途(仅用于某个具体功能or莫类型功能通用)、使用方法、效果、备注(有哪些要注意的地方)
+
+样式
+1.TabControlWithUnderLineStyle  
+样式位置:PDF Office\Styles\TabControlStyle.xaml
+用途:用于调整HeaderPanel水平居中(不影响Content位置的前提下)
+目前用于:阅读页工具栏、BOTA多页签部分

+ 89 - 2
PDF Office/ViewModels/Dialog/VerifyPassWordDialogViewModel.cs

@@ -1,14 +1,101 @@
-using Prism.Mvvm;
+using ComPDFKit.PDFDocument;
+using Prism.Commands;
+using Prism.Mvvm;
+using Prism.Services.Dialogs;
 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using System.Windows;
 
 namespace PDF_Office.ViewModels.Dialog
 {
-    public class VerifyPassWordDialogViewModel:BindableBase
+    public class VerifyPassWordDialogViewModel : BindableBase, IDialogAware
     {
+        public string Title => "VerifyPassWordDialog";
 
+        public string WarningText => "Error PassWord";
+
+        public event Action<IDialogResult> RequestClose;
+
+        public DelegateCommand OKCommand { get; set; }
+
+        public DelegateCommand CancelCommand { get; set; }
+
+        private string input;
+
+        public string Input
+        {
+            get { return input; }
+            set
+            {
+                SetProperty(ref input, value);
+                ShowWarning = Visibility.Collapsed;
+            }
+        }
+
+        private Visibility showWarning = Visibility.Collapsed;
+
+        public Visibility ShowWarning
+        {
+            get { return showWarning; }
+            set
+            {
+                SetProperty(ref showWarning, value);
+            }
+        }
+
+
+
+        private CPDFDocument document;
+
+        public VerifyPassWordDialogViewModel()
+        {
+            OKCommand = new DelegateCommand(OK);
+            CancelCommand = new DelegateCommand(Cancel);
+        }
+
+        private void OK()
+        {
+            if (string.IsNullOrEmpty(input))
+                return;
+            bool result = document.UnlockWithPassword(input.Trim());
+            if (!result)
+            {
+                ShowWarning = Visibility.Visible;
+                return;
+            }
+            var dialogresult = new DialogResult(ButtonResult.OK);
+            dialogresult.Parameters.Add("PassWord", input.Trim());
+            RequestClose.Invoke(dialogresult);
+        }
+
+        private void Cancel()
+        {
+            RequestClose.Invoke(new DialogResult(ButtonResult.Cancel));
+        }
+
+
+        public bool CanCloseDialog()
+        {
+            return true;
+        }
+
+        public void OnDialogClosed()
+        {
+
+        }
+
+        public void OnDialogOpened(IDialogParameters parameters)
+        {
+            CPDFDocument doc = null;
+            parameters.TryGetValue<CPDFDocument>("PDFDocument", out doc);
+            if (doc != null)
+            {
+                document = doc;
+            }
+
+        }
     }
 }

+ 71 - 12
PDF Office/Views/Dialog/VerifyPassWordDialog.xaml

@@ -1,12 +1,71 @@
-<Window x:Class="PDF_Office.Views.Dialog.VerifyPassWordDialog"
-        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
-        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
-        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
-        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
-        xmlns:local="clr-namespace:PDF_Office.Views.Dialog"
-        mc:Ignorable="d"
-        Title="VerifyPassWordDialog" Height="450" Width="800">
-    <Grid>
-        
-    </Grid>
-</Window>
+<UserControl
+    x:Class="PDF_Office.Views.Dialog.VerifyPassWordDialog"
+    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+    xmlns:dialog="clr-namespace:PDF_Office.ViewModels.Dialog"
+    xmlns:local="clr-namespace:PDF_Office.Views.Dialog"
+    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+    xmlns:prism="http://prismlibrary.com/"
+    Width="600"
+    Height="400"
+    d:DataContext="{d:DesignInstance Type=dialog:VerifyPassWordDialogViewModel}"
+    prism:ViewModelLocator.AutoWireViewModel="True"
+    mc:Ignorable="d">
+    <prism:Dialog.WindowStyle>
+        <Style TargetType="{x:Type Window}">
+            <Setter Property="Title" Value="{Binding Title}" />
+            <Setter Property="prism:Dialog.WindowStartupLocation" Value="CenterScreen" />
+            <Setter Property="ShowInTaskbar" Value="False" />
+            <Setter Property="SizeToContent" Value="WidthAndHeight" />
+        </Style>
+    </prism:Dialog.WindowStyle>
+    <StackPanel VerticalAlignment="Center">
+        <TextBlock
+            Margin="0,15"
+            FontSize="14"
+            Text="Please enter the password to unpass the file" />
+        <TextBox
+            Height="32"
+            Margin="20,0"
+            VerticalContentAlignment="Center"
+            FontSize="14"
+            Text="{Binding Input, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
+            <TextBox.Style>
+                <Style TargetType="{x:Type TextBox}">
+                    <Style.Triggers>
+                        <DataTrigger Binding="{Binding ShowWarning}" Value="Visible">
+                            <Setter Property="BorderBrush" Value="Red" />
+                        </DataTrigger>
+                    </Style.Triggers>
+                </Style>
+            </TextBox.Style>
+        </TextBox>
+        <Grid>
+            <TextBlock
+                Name="TxtInput"
+                Margin="20,0"
+                HorizontalAlignment="Left"
+                FontSize="14"
+                Foreground="Red"
+                Text="{Binding WarningText}"
+                Visibility="{Binding ShowWarning}" />
+            <StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
+                <Button
+                    Name="BtnOK"
+                    Width="120"
+                    Height="32"
+                    Margin="10,10"
+                    Command="{Binding OKCommand}"
+                    Content="OK" />
+                <Button
+                    Name="BtnCancel"
+                    Width="120"
+                    Height="32"
+                    Margin="10,0"
+                    Command="{Binding CancelCommand}"
+                    Content="Cancel" />
+            </StackPanel>
+        </Grid>
+    </StackPanel>
+</UserControl>

+ 1 - 1
PDF Office/Views/Dialog/VerifyPassWordDialog.xaml.cs

@@ -17,7 +17,7 @@ namespace PDF_Office.Views.Dialog
     /// <summary>
     /// VerifyPassWordDialog.xaml 的交互逻辑
     /// </summary>
-    public partial class VerifyPassWordDialog : Window
+    public partial class VerifyPassWordDialog : UserControl
     {
         public VerifyPassWordDialog()
         {