DigitalSignatureControl.xaml.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. using System;
  2. using System.ComponentModel;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Runtime.CompilerServices;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Controls.Primitives;
  9. using System.Windows.Input;
  10. using System.Windows.Media;
  11. using Compdfkit_Tools.Helper;
  12. using ComPDFKit.DigitalSign;
  13. using ComPDFKit.PDFAnnotation.Form;
  14. using ComPDFKitViewer;
  15. namespace Compdfkit_Tools.PDFControl
  16. {
  17. public partial class DigitalSignatureControl : UserControl, INotifyPropertyChanged
  18. {
  19. #region Properties
  20. private bool isFirstLoad = true;
  21. public PDFViewControl PDFViewControl = new PDFViewControl();
  22. private SignatureStatusBarControl signatureStatusBarControl;
  23. private PanelState panelState = PanelState.GetInstance();
  24. private CPDFDisplaySettingsControl displaySettingsControl = null;
  25. private CPDFSignatureWidget currentSignatureWidget;
  26. private double[] zoomLevelList = { 1f, 8f, 12f, 25, 33f, 50, 66f, 75, 100, 125, 150, 200, 300, 400, 600, 800, 1000 };
  27. public event EventHandler<bool> OnCanSaveChanged;
  28. public event EventHandler<string> AfterFillSignature;
  29. public event EventHandler SignatureStatusChanged;
  30. public event PropertyChangedEventHandler PropertyChanged;
  31. protected void OnPropertyChanged([CallerMemberName] string name = null)
  32. {
  33. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
  34. }
  35. /// <summary>
  36. /// Whether the undo operation can be performed.
  37. /// </summary>
  38. public bool CanUndo
  39. {
  40. get
  41. {
  42. if (PDFViewControl != null && PDFViewControl.PDFView != null)
  43. {
  44. return PDFViewControl.PDFView.UndoManager.CanUndo;
  45. }
  46. return false;
  47. }
  48. }
  49. /// <summary>
  50. /// Whether the redo operation can be performed.
  51. /// </summary>
  52. public bool CanRedo
  53. {
  54. get
  55. {
  56. if (PDFViewControl != null && PDFViewControl.PDFView != null)
  57. {
  58. return PDFViewControl.PDFView.UndoManager.CanRedo;
  59. }
  60. return false;
  61. }
  62. }
  63. /// <summary>
  64. /// Whether the save operation can be performed.
  65. /// </summary>
  66. public 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. #endregion
  78. /// <summary>
  79. /// A digital signature control should be used in a window, and it should be initialized with a PDFViewer.
  80. /// Certificates will be saved in the TrustedFolder.
  81. /// </summary>
  82. public DigitalSignatureControl()
  83. {
  84. InitializeComponent();
  85. DataContext = this;
  86. string trustedFolder = AppDomain.CurrentDomain.BaseDirectory + @"\TrustedFolder\";
  87. if (!Directory.Exists(trustedFolder))
  88. {
  89. Directory.CreateDirectory(trustedFolder);
  90. }
  91. CPDFSignature.SignCertTrustedFolder = trustedFolder;
  92. }
  93. #region Public Method
  94. /// <summary>
  95. /// Disconnect all the specified elements that are already the logical children of another element. And reset bar control status.
  96. /// </summary>
  97. public void ClearViewerControl()
  98. {
  99. PDFGrid.Child = null;
  100. BotaContainer.Child = null;
  101. PropertyContainer.Child = null;
  102. displaySettingsControl = null;
  103. SignatureStatusBorder.Child = null;
  104. DigitalSignatureBarControl.ClearAllToolState();
  105. }
  106. /// <summary>
  107. /// Init controls with pdfViewer, and load events.
  108. /// </summary>
  109. /// <param name="pdfViewer"></param>
  110. public void InitWithPDFViewer(CPDFViewer pdfViewer)
  111. {
  112. PDFViewControl.PDFView = pdfViewer;
  113. PDFGrid.Child = PDFViewControl;
  114. FloatPageTool.InitWithPDFViewer(pdfViewer);
  115. PDFViewControl.PDFView.SetMouseMode(MouseModes.Viewer);
  116. PDFViewControl.PDFView.SetShowLink(true);
  117. PDFViewControl.PDFView.SetFormFieldHighlight(true);
  118. PDFViewControl.PDFView.UndoManager.ClearHistory();
  119. DigitalSignatureBarControl.DigitalSignatureActionChanged -= DigitalSignatureBarControl_DigitalSignatureActionChanged;
  120. DigitalSignatureBarControl.DigitalSignatureActionChanged += DigitalSignatureBarControl_DigitalSignatureActionChanged;
  121. PDFViewControl.PDFView.WidgetClickHandler -= PDFView_WidgetClickHandler;
  122. PDFViewControl.PDFView.WidgetClickHandler += PDFView_WidgetClickHandler;
  123. PDFViewControl.PDFView.AnnotCommandHandler -= PDFView_AnnotCommandHandler;
  124. PDFViewControl.PDFView.AnnotCommandHandler += PDFView_AnnotCommandHandler;
  125. panelState.PropertyChanged -= PanelState_PropertyChanged;
  126. panelState.PropertyChanged += PanelState_PropertyChanged;
  127. }
  128. /// <summary>
  129. /// Separately, init PDFView and load undo manager event. Only use for ensuring SaveBtn is enabled after deleting digital signature on Viewer mode.
  130. /// </summary>
  131. /// <param name="pdfViewer"></param>
  132. public void LoadUndoManagerEvent(CPDFViewer pdfViewer)
  133. {
  134. PDFViewControl.PDFView = pdfViewer;
  135. PDFViewControl.PDFView.UndoManager.PropertyChanged -= UndoManager_PropertyChanged;
  136. PDFViewControl.PDFView.UndoManager.PropertyChanged += UndoManager_PropertyChanged;
  137. }
  138. /// <summary>
  139. /// Set child for BOTAContainer with BOTABarControl.
  140. /// </summary>
  141. /// <param name="botaControl"></param>
  142. public void SetBOTAContainer(CPDFBOTABarControl botaControl)
  143. {
  144. BotaContainer.Child = botaControl;
  145. }
  146. /// <summary>
  147. /// Create a certificate info dialog with signature.
  148. /// </summary>
  149. /// <param name="sender"></param>
  150. /// <param name="e">Signature to init certificate</param>
  151. public void ViewCertificateEvent(object sender, CPDFSignature e)
  152. {
  153. Window parentWindow = Window.GetWindow((DependencyObject)sender);
  154. ViewCertificateDialog dialog = new ViewCertificateDialog()
  155. {
  156. Owner = parentWindow
  157. };
  158. dialog.InitCertificateList(e);
  159. dialog.CertificateInfoControl.TrustCertificateEvent += (o, args) =>
  160. {
  161. SignatureStatusChanged?.Invoke(this, null);
  162. };
  163. if (parentWindow is VerifyDigitalSignatureControl verifyControl)
  164. {
  165. dialog.CertificateInfoControl.TrustCertificateEvent += (o, args) =>
  166. {
  167. verifyControl.InitWithSignature(e);
  168. };
  169. }
  170. dialog.ShowDialog();
  171. }
  172. /// <summary>
  173. /// Set display settings control.
  174. /// </summary>
  175. /// <param name="displaySettingsControl"></param>
  176. public void SetDisplaySettingsControl(CPDFDisplaySettingsControl displaySettingsControl)
  177. {
  178. this.displaySettingsControl = displaySettingsControl;
  179. }
  180. /// <summary>
  181. /// Set visibility of SignatureStatusBarControl according its status.
  182. /// </summary>
  183. /// <param name="signatureStatusBarControl"></param>
  184. public void SetSignatureStatusBarControl(SignatureStatusBarControl signatureStatusBarControl)
  185. {
  186. this.signatureStatusBarControl = signatureStatusBarControl;
  187. SignatureStatusBorder.Child = this.signatureStatusBarControl;
  188. if (signatureStatusBarControl.Status != SignatureStatus.None)
  189. {
  190. SignatureStatusBorder.Visibility = Visibility.Visible;
  191. }
  192. else
  193. {
  194. SignatureStatusBorder.Visibility = Visibility.Collapsed;
  195. }
  196. }
  197. /// <summary>
  198. /// Create a signature info dialog with signature.
  199. /// </summary>
  200. /// <param name="sender"></param>
  201. /// <param name="e">Signature to be displayed</param>
  202. public void ViewSignatureEvent(object sender, CPDFSignature e)
  203. {
  204. Window parentWindow = Window.GetWindow((DependencyObject)sender);
  205. VerifyDigitalSignatureControl dialog = new VerifyDigitalSignatureControl()
  206. {
  207. Owner = parentWindow
  208. };
  209. dialog.ViewCertificateEvent -= ViewCertificateEvent;
  210. dialog.ViewCertificateEvent += ViewCertificateEvent;
  211. dialog.InitWithSignature(e);
  212. dialog.ShowDialog();
  213. }
  214. #endregion
  215. #region Private Method
  216. /// <summary>
  217. /// Get current time as a string.
  218. /// </summary>
  219. /// <returns></returns>
  220. private string GetTime()
  221. {
  222. DateTime dateTime = DateTime.Now;
  223. return " " + dateTime.ToString("yyyy-MM-dd HH:mm:ss.fff");
  224. }
  225. /// <summary>
  226. /// Create a signature field.
  227. /// </summary>
  228. private void CreateSign()
  229. {
  230. PDFViewControl.PDFView.SetMouseMode(MouseModes.FormEditTool);
  231. WidgetSignArgs signArgs = new WidgetSignArgs
  232. {
  233. LineWidth = 1,
  234. LineColor = Colors.Black,
  235. FieldName = "Signature" + GetTime()
  236. };
  237. PDFViewControl.PDFView.SetToolParam(signArgs);
  238. }
  239. /// <summary>
  240. /// Expand or collapse left panel.
  241. /// </summary>
  242. /// <param name="isExpand"></param>
  243. private void ExpandLeftPanel(bool isExpand)
  244. {
  245. BotaContainer.Visibility = isExpand ? Visibility.Visible : Visibility.Collapsed;
  246. Splitter.Visibility = isExpand ? Visibility.Visible : Visibility.Collapsed;
  247. if (isExpand)
  248. {
  249. BodyGrid.ColumnDefinitions[0].Width = new GridLength(320);
  250. BodyGrid.ColumnDefinitions[1].Width = new GridLength(15);
  251. }
  252. else
  253. {
  254. BodyGrid.ColumnDefinitions[0].Width = new GridLength(0);
  255. BodyGrid.ColumnDefinitions[1].Width = new GridLength(0);
  256. }
  257. }
  258. /// <summary>
  259. /// Expand or collapse right panel.
  260. /// </summary>
  261. /// <param name="propertytPanel"></param>
  262. /// <param name="visible"></param>
  263. private void ExpandRightPropertyPanel(UIElement propertytPanel, Visibility visible)
  264. {
  265. PropertyContainer.Width = 260;
  266. PropertyContainer.Child = propertytPanel;
  267. PropertyContainer.Visibility = visible;
  268. }
  269. #endregion
  270. #region Private Command Event
  271. /// <summary>
  272. /// Click event of signature field.
  273. /// </summary>
  274. /// <param name="sender"></param>
  275. /// <param name="e"></param>
  276. private void PDFView_WidgetClickHandler(object sender, WidgetArgs e)
  277. {
  278. var signatureWidget = (e as WidgetSignArgs).Sign;
  279. CPDFSignature sig = signatureWidget.GetSignature(PDFViewControl.PDFView.Document);
  280. if (signatureWidget.IsSigned() && sig!=null && sig?.SignerList.Count > 0)
  281. {
  282. ViewSignatureEvent(sender, sig);
  283. }
  284. else
  285. {
  286. Window parentWindow = Window.GetWindow((DependencyObject)sender);
  287. AddCertificationDialog addCertificationControl = new AddCertificationDialog
  288. {
  289. Owner = parentWindow
  290. };
  291. currentSignatureWidget = signatureWidget;
  292. addCertificationControl.FillSignatureEvent -= AddCertificationControl_FillSignatureEvent;
  293. addCertificationControl.FillSignatureEvent += AddCertificationControl_FillSignatureEvent;
  294. addCertificationControl.ShowDialog();
  295. }
  296. }
  297. /// <summary>
  298. /// Event of filling a signature.
  299. /// </summary>
  300. /// <param name="sender"></param>
  301. /// <param name="e"></param>
  302. private void AddCertificationControl_FillSignatureEvent(object sender, CertificateAccess e)
  303. {
  304. FillDigitalSignatureDialog fillDigitalSignatureDialog = new FillDigitalSignatureDialog
  305. {
  306. FilePath = e.filePath,
  307. Password = e.password,
  308. SignatureWidget = currentSignatureWidget,
  309. Document = PDFViewControl.PDFView.Document,
  310. Owner = Window.GetWindow(this)
  311. };
  312. fillDigitalSignatureDialog.AfterFillSignature += FillDigitalSignatureDialog_AfterFillSignature; ;
  313. fillDigitalSignatureDialog.ShowDialog();
  314. }
  315. /// <summary>
  316. /// Event of after filling a signature.
  317. /// </summary>
  318. /// <param name="sender"></param>
  319. /// <param name="e"></param>
  320. private void FillDigitalSignatureDialog_AfterFillSignature(object sender, string e)
  321. {
  322. AfterFillSignature?.Invoke(this, e);
  323. }
  324. /// <summary>
  325. /// Click event of buttons in digital SignatureBarControl.
  326. /// </summary>
  327. /// <param name="sender"></param>
  328. /// <param name="e"></param>
  329. private void DigitalSignatureBarControl_DigitalSignatureActionChanged(object sender, Common.CPDFDigitalSignatureBarControl.DigitalSignatureAction e)
  330. {
  331. if (e == Common.CPDFDigitalSignatureBarControl.DigitalSignatureAction.AddSignatureField)
  332. {
  333. CreateSign();
  334. }
  335. else if (e == Common.CPDFDigitalSignatureBarControl.DigitalSignatureAction.Signing)
  336. {
  337. PDFViewControl.PDFView.SetMouseMode(MouseModes.Viewer);
  338. }
  339. else if (e == Common.CPDFDigitalSignatureBarControl.DigitalSignatureAction.VerifySignature)
  340. {
  341. ToggleButton button = sender as ToggleButton;
  342. button.IsChecked = false;
  343. SignatureStatusChanged?.Invoke(this, null);
  344. }
  345. }
  346. /// <summary>
  347. /// Property changed event of PanelState.
  348. /// </summary>
  349. /// <param name="sender"></param>
  350. /// <param name="e"></param>
  351. private void PanelState_PropertyChanged(object sender, PropertyChangedEventArgs e)
  352. {
  353. if (e.PropertyName == nameof(PanelState.IsLeftPanelExpand))
  354. {
  355. ExpandLeftPanel(panelState.IsLeftPanelExpand);
  356. }
  357. else if (e.PropertyName == nameof(PanelState.RightPanel))
  358. {
  359. if (panelState.RightPanel == PanelState.RightPanelState.ViewSettings)
  360. {
  361. ExpandRightPropertyPanel(displaySettingsControl, Visibility.Visible);
  362. }
  363. else
  364. {
  365. ExpandRightPropertyPanel(null, Visibility.Collapsed);
  366. }
  367. }
  368. }
  369. /// <summary>
  370. /// Event of UndoManager property changed.
  371. /// </summary>
  372. private void UndoManager_PropertyChanged(object sender, PropertyChangedEventArgs e)
  373. {
  374. OnPropertyChanged(e.PropertyName);
  375. if (e.PropertyName == "CanSave")
  376. {
  377. OnCanSaveChanged?.Invoke(this, CanSave);
  378. }
  379. }
  380. /// <summary>
  381. /// Command event of undo operation.
  382. /// </summary>
  383. /// <param name="sender"></param>
  384. /// <param name="e"></param>
  385. private void CommandBinding_Executed_Undo(object sender, ExecutedRoutedEventArgs e)
  386. {
  387. if (PDFViewControl != null && PDFViewControl.PDFView != null && CanUndo)
  388. {
  389. PDFViewControl.PDFView.UndoManager?.Undo();
  390. }
  391. }
  392. /// <summary>
  393. /// Command event of redo operation.
  394. /// </summary>
  395. /// <param name="sender"></param>
  396. /// <param name="e"></param>
  397. private void CommandBinding_Executed_Redo(object sender, ExecutedRoutedEventArgs e)
  398. {
  399. if (PDFViewControl != null && PDFViewControl.PDFView != null && CanUndo)
  400. {
  401. PDFViewControl.PDFView.UndoManager?.Redo();
  402. }
  403. }
  404. /// <summary>
  405. /// Click event of undo button.
  406. /// </summary>
  407. /// <param name="sender"></param>
  408. /// <param name="e"></param>
  409. private void UndoButton_Click(object sender, RoutedEventArgs e)
  410. {
  411. if (PDFViewControl != null && PDFViewControl.PDFView != null && CanUndo)
  412. {
  413. PDFViewControl.PDFView.UndoManager?.Undo();
  414. }
  415. }
  416. /// <summary>
  417. /// Click event of redo button.
  418. /// </summary>
  419. /// <param name="sender"></param>
  420. /// <param name="e"></param>
  421. private void RedoButton_Click(object sender, RoutedEventArgs e)
  422. {
  423. if (PDFViewControl != null && PDFViewControl.PDFView != null && CanRedo)
  424. {
  425. PDFViewControl.PDFView.UndoManager?.Redo();
  426. }
  427. }
  428. #endregion
  429. #region ContextMenu
  430. /// <summary>
  431. /// Right click context menu
  432. /// </summary>
  433. /// <param name="sender"></param>
  434. /// <param name="e"></param>
  435. private void PDFView_AnnotCommandHandler(object sender, AnnotCommandArgs e)
  436. {
  437. if (e != null && e.CommandType == CommandType.Context)
  438. {
  439. if (e.CommandTarget == TargetType.WidgetView)
  440. {
  441. e.Handle = true;
  442. e.PopupMenu = new ContextMenu();
  443. var sign = e.Sign.GetSignature(PDFViewControl.PDFView.Document);
  444. if (e.Sign.IsSigned() && sign != null && sign.SignerList.Any())
  445. {
  446. MenuItem DeleteMenu = new MenuItem()
  447. { Header = "Delete" };
  448. DeleteMenu.Click += (o, args) =>
  449. {
  450. PDFViewControl.PDFView.Document.RemoveSignature(sign, true);
  451. e.Sign.ResetForm();
  452. e.Sign.SetIsLocked(false);
  453. PDFViewControl.PDFView.ReloadVisibleAnnots();
  454. PDFViewControl.PDFView.UndoManager.CanSave = true;
  455. SignatureStatusChanged?.Invoke(this, null);
  456. };
  457. e.PopupMenu.Items.Add(DeleteMenu);
  458. }
  459. else
  460. {
  461. e.PopupMenu.Items.Add(new MenuItem()
  462. { Header = "Copy", Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
  463. e.PopupMenu.Items.Add(new MenuItem()
  464. { Header = "Cut", Command = ApplicationCommands.Cut, CommandTarget = (UIElement)sender });
  465. e.PopupMenu.Items.Add(new MenuItem()
  466. { Header = "Delete", Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
  467. }
  468. }
  469. else
  470. {
  471. e.Handle = true;
  472. e.PopupMenu = new ContextMenu();
  473. e.PopupMenu.Items.Add(new MenuItem()
  474. { Header = "Paste", Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
  475. e.PopupMenu.Items.Add(new Separator());
  476. MenuItem fitWidthMenu = new MenuItem();
  477. fitWidthMenu.Header = "Automatically Resize";
  478. fitWidthMenu.Click += (o, p) =>
  479. {
  480. if (PDFViewControl != null)
  481. {
  482. PDFViewControl.PDFView?.ChangeFitMode(FitMode.FitWidth);
  483. }
  484. };
  485. e.PopupMenu.Items.Add(fitWidthMenu);
  486. MenuItem fitSizeMenu = new MenuItem();
  487. fitSizeMenu.Header = "Actual Size";
  488. fitSizeMenu.Click += (o, p) =>
  489. {
  490. if (PDFViewControl != null)
  491. {
  492. PDFViewControl.PDFView?.ChangeFitMode(FitMode.FitSize);
  493. }
  494. };
  495. e.PopupMenu.Items.Add(fitSizeMenu);
  496. MenuItem zoomInMenu = new MenuItem();
  497. zoomInMenu.Header = "Zoom In";
  498. zoomInMenu.Click += (o, p) =>
  499. {
  500. if (PDFViewControl != null)
  501. {
  502. double newZoom = CommandHelper.CheckZoomLevel(zoomLevelList,
  503. PDFViewControl.PDFView.ZoomFactor + 0.01, true);
  504. PDFViewControl.PDFView?.Zoom(newZoom);
  505. }
  506. };
  507. e.PopupMenu.Items.Add(zoomInMenu);
  508. MenuItem zoomOutMenu = new MenuItem();
  509. zoomOutMenu.Header = "Zoom Out";
  510. zoomOutMenu.Click += (o, p) =>
  511. {
  512. if (PDFViewControl != null)
  513. {
  514. double newZoom = CommandHelper.CheckZoomLevel(zoomLevelList,
  515. PDFViewControl.PDFView.ZoomFactor - 0.01, false);
  516. PDFViewControl.PDFView?.Zoom(newZoom);
  517. }
  518. };
  519. e.PopupMenu.Items.Add(zoomOutMenu);
  520. e.PopupMenu.Items.Add(new Separator());
  521. MenuItem singleView = new MenuItem();
  522. singleView.Header = "Single Page";
  523. singleView.Click += (o, p) =>
  524. {
  525. if (PDFViewControl != null)
  526. {
  527. PDFViewControl.PDFView?.ChangeViewMode(ViewMode.Single);
  528. }
  529. };
  530. e.PopupMenu.Items.Add(singleView);
  531. MenuItem singleContinuousView = new MenuItem();
  532. singleContinuousView.Header = "Single Page Continuous";
  533. singleContinuousView.Click += (o, p) =>
  534. {
  535. if (PDFViewControl != null)
  536. {
  537. PDFViewControl.PDFView?.ChangeViewMode(ViewMode.SingleContinuous);
  538. }
  539. };
  540. e.PopupMenu.Items.Add(singleContinuousView);
  541. MenuItem doubleView = new MenuItem();
  542. doubleView.Header = "Two Pages";
  543. doubleView.Click += (o, p) =>
  544. {
  545. if (PDFViewControl != null)
  546. {
  547. PDFViewControl.PDFView?.ChangeViewMode(ViewMode.Double);
  548. }
  549. };
  550. e.PopupMenu.Items.Add(doubleView);
  551. MenuItem doubleContinuousView = new MenuItem();
  552. doubleContinuousView.Header = "Two Pages Continuous";
  553. doubleContinuousView.Click += (o, p) =>
  554. {
  555. if (PDFViewControl != null)
  556. {
  557. PDFViewControl.PDFView?.ChangeViewMode(ViewMode.DoubleContinuous);
  558. }
  559. };
  560. e.PopupMenu.Items.Add(doubleContinuousView);
  561. MenuItem resetFormMenu = new MenuItem();
  562. resetFormMenu.Header = "Reset Forms";
  563. resetFormMenu.Click += (o, p) =>
  564. {
  565. if (PDFViewControl != null)
  566. {
  567. PDFViewControl.PDFView?.ResetForm(null);
  568. }
  569. };
  570. e.PopupMenu.Items.Add(new Separator());
  571. e.PopupMenu.Items.Add(resetFormMenu);
  572. }
  573. }
  574. else
  575. {
  576. e.DoCommand();
  577. }
  578. }
  579. #endregion
  580. #region Load Unload Event
  581. /// <summary>
  582. /// Load event
  583. /// </summary>
  584. /// <param name="sender"></param>
  585. /// <param name="e"></param>
  586. private void UserControl_Loaded(object sender, RoutedEventArgs e)
  587. {
  588. }
  589. /// <summary>
  590. /// Unload event
  591. /// </summary>
  592. /// <param name="sender"></param>
  593. /// <param name="e"></param>
  594. private void UserControl_Unloaded(object sender, RoutedEventArgs e)
  595. {
  596. PDFViewControl.PDFView.AnnotCommandHandler -= PDFView_AnnotCommandHandler;
  597. PDFViewControl.PDFView.WidgetClickHandler -= PDFView_WidgetClickHandler;
  598. }
  599. #endregion
  600. }
  601. }