123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- using Compdfkit_Tools.PDFControl;
- using ComPDFKitViewer.PdfViewer;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Linq;
- using System.Runtime.CompilerServices;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- namespace Compdfkit_Tools.PDFControl
- {
- /// <summary>
- /// DigitalSignatureControl.xaml 的交互逻辑
- /// </summary>
- public partial class DigitalSignatureControl : UserControl, INotifyPropertyChanged
- {
- private bool isFirstLoad = true;
- public PDFViewControl PdfViewControl = new PDFViewControl();
- private bool _isActive = false;
- public event EventHandler<bool> OnCanSaveChanged;
- public event PropertyChangedEventHandler PropertyChanged;
- protected void OnPropertyChanged([CallerMemberName] string name = null)
- {
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
- }
- public bool IsActive
- {
- get => _isActive;
- set
- {
- _isActive = value;
- OnPropertyChanged();
- }
- }
- public bool CanUndo
- {
- get
- {
- if (PdfViewControl != null && PdfViewControl.PDFView != null)
- {
- return PdfViewControl.PDFView.UndoManager.CanUndo;
- }
- return false;
- }
- }
- public bool CanRedo
- {
- get
- {
- if (PdfViewControl != null && PdfViewControl.PDFView != null)
- {
- return PdfViewControl.PDFView.UndoManager.CanRedo;
- }
- return false;
- }
- }
- private bool CanSave
- {
- get
- {
- if (PdfViewControl != null && PdfViewControl.PDFView != null)
- {
- return PdfViewControl.PDFView.UndoManager.CanSave;
- }
- return false;
- }
- }
- public DigitalSignatureControl()
- {
- InitializeComponent();
- DataContext = this;
- }
- public void ClearViewerControl()
- {
- PDFGrid.Child = null;
- BotaContainer.Child = null;
- PropertyContainer.Child = null;
- }
- public void InitWithPDFViewer(CPDFViewer pdfViewer)
- {
- PdfViewControl.PDFView = pdfViewer;
- PDFGrid.Child = PdfViewControl;
- FloatPageTool.InitWithPDFViewer(pdfViewer);
- InitialControl();
- }
- private void InitialControl()
- {
- PdfViewControl.PDFView?.SetMouseMode(MouseModes.Viewer);
- //PdfViewControl.PDFView?.Load();
- PdfViewControl.PDFView?.SetShowLink(true);
- PDFGrid.Child = PdfViewControl;
- PdfViewControl.PDFView.UndoManager.PropertyChanged -= UndoManager_PropertyChanged;
- PdfViewControl.PDFView.UndoManager.PropertyChanged += UndoManager_PropertyChanged;
- PdfViewControl.PDFView.SetFormFieldHighlight(true);
- }
- /// <summary>
- /// Undo Redo Event Noitfy
- /// </summary>
- private void UndoManager_PropertyChanged(object sender, PropertyChangedEventArgs e)
- {
- OnPropertyChanged(e.PropertyName);
- if (e.PropertyName == "CanSave")
- {
- OnCanSaveChanged?.Invoke(this, CanSave);
- }
- }
- private void CommandBinding_Executed_Undo(object sender, ExecutedRoutedEventArgs e)
- {
- if (PdfViewControl != null && PdfViewControl.PDFView != null && CanUndo)
- {
- PdfViewControl.PDFView.UndoManager?.Undo();
- }
- }
- private void CommandBinding_Executed_Redo(object sender, ExecutedRoutedEventArgs e)
- {
- if (PdfViewControl != null && PdfViewControl.PDFView != null && CanUndo)
- {
- PdfViewControl.PDFView.UndoManager?.Redo();
- }
- }
- private void UndoButton_Click(object sender, RoutedEventArgs e)
- {
- if (PdfViewControl != null && PdfViewControl.PDFView != null && CanUndo)
- {
- PdfViewControl.PDFView.UndoManager?.Undo();
- }
- }
- private void RedoButton_Click(object sender, RoutedEventArgs e)
- {
- if (PdfViewControl != null && PdfViewControl.PDFView != null && CanUndo)
- {
- PdfViewControl.PDFView.UndoManager?.Redo();
- }
- }
- }
- }
|