DigitalSignatureControl.xaml.cs 25 KB

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