DigitalSignatureControl.xaml.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. using Compdfkit_Tools.PDFControl;
  2. using ComPDFKitViewer.PdfViewer;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Linq;
  7. using System.Runtime.CompilerServices;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows;
  11. using System.Windows.Controls;
  12. using System.Windows.Data;
  13. using System.Windows.Documents;
  14. using System.Windows.Input;
  15. using System.Windows.Media;
  16. using System.Windows.Media.Imaging;
  17. using System.Windows.Navigation;
  18. using System.Windows.Shapes;
  19. namespace Compdfkit_Tools.PDFControl
  20. {
  21. /// <summary>
  22. /// DigitalSignatureControl.xaml 的交互逻辑
  23. /// </summary>
  24. public partial class DigitalSignatureControl : UserControl, INotifyPropertyChanged
  25. {
  26. private bool isFirstLoad = true;
  27. public PDFViewControl PdfViewControl = new PDFViewControl();
  28. private bool _isActive = false;
  29. public event EventHandler<bool> OnCanSaveChanged;
  30. public event PropertyChangedEventHandler PropertyChanged;
  31. protected void OnPropertyChanged([CallerMemberName] string name = null)
  32. {
  33. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
  34. }
  35. public bool IsActive
  36. {
  37. get => _isActive;
  38. set
  39. {
  40. _isActive = value;
  41. OnPropertyChanged();
  42. }
  43. }
  44. public bool CanUndo
  45. {
  46. get
  47. {
  48. if (PdfViewControl != null && PdfViewControl.PDFView != null)
  49. {
  50. return PdfViewControl.PDFView.UndoManager.CanUndo;
  51. }
  52. return false;
  53. }
  54. }
  55. public bool CanRedo
  56. {
  57. get
  58. {
  59. if (PdfViewControl != null && PdfViewControl.PDFView != null)
  60. {
  61. return PdfViewControl.PDFView.UndoManager.CanRedo;
  62. }
  63. return false;
  64. }
  65. }
  66. private bool CanSave
  67. {
  68. get
  69. {
  70. if (PdfViewControl != null && PdfViewControl.PDFView != null)
  71. {
  72. return PdfViewControl.PDFView.UndoManager.CanSave;
  73. }
  74. return false;
  75. }
  76. }
  77. public DigitalSignatureControl()
  78. {
  79. InitializeComponent();
  80. DataContext = this;
  81. }
  82. public void ClearViewerControl()
  83. {
  84. PDFGrid.Child = null;
  85. BotaContainer.Child = null;
  86. PropertyContainer.Child = null;
  87. }
  88. public void InitWithPDFViewer(CPDFViewer pdfViewer)
  89. {
  90. PdfViewControl.PDFView = pdfViewer;
  91. PDFGrid.Child = PdfViewControl;
  92. FloatPageTool.InitWithPDFViewer(pdfViewer);
  93. InitialControl();
  94. }
  95. private void InitialControl()
  96. {
  97. PdfViewControl.PDFView?.SetMouseMode(MouseModes.Viewer);
  98. //PdfViewControl.PDFView?.Load();
  99. PdfViewControl.PDFView?.SetShowLink(true);
  100. PDFGrid.Child = PdfViewControl;
  101. PdfViewControl.PDFView.UndoManager.PropertyChanged -= UndoManager_PropertyChanged;
  102. PdfViewControl.PDFView.UndoManager.PropertyChanged += UndoManager_PropertyChanged;
  103. PdfViewControl.PDFView.SetFormFieldHighlight(true);
  104. }
  105. /// <summary>
  106. /// Undo Redo Event Noitfy
  107. /// </summary>
  108. private void UndoManager_PropertyChanged(object sender, PropertyChangedEventArgs e)
  109. {
  110. OnPropertyChanged(e.PropertyName);
  111. if (e.PropertyName == "CanSave")
  112. {
  113. OnCanSaveChanged?.Invoke(this, CanSave);
  114. }
  115. }
  116. private void CommandBinding_Executed_Undo(object sender, ExecutedRoutedEventArgs e)
  117. {
  118. if (PdfViewControl != null && PdfViewControl.PDFView != null && CanUndo)
  119. {
  120. PdfViewControl.PDFView.UndoManager?.Undo();
  121. }
  122. }
  123. private void CommandBinding_Executed_Redo(object sender, ExecutedRoutedEventArgs e)
  124. {
  125. if (PdfViewControl != null && PdfViewControl.PDFView != null && CanUndo)
  126. {
  127. PdfViewControl.PDFView.UndoManager?.Redo();
  128. }
  129. }
  130. private void UndoButton_Click(object sender, RoutedEventArgs e)
  131. {
  132. if (PdfViewControl != null && PdfViewControl.PDFView != null && CanUndo)
  133. {
  134. PdfViewControl.PDFView.UndoManager?.Undo();
  135. }
  136. }
  137. private void RedoButton_Click(object sender, RoutedEventArgs e)
  138. {
  139. if (PdfViewControl != null && PdfViewControl.PDFView != null && CanUndo)
  140. {
  141. PdfViewControl.PDFView.UndoManager?.Redo();
  142. }
  143. }
  144. }
  145. }