DigitalSignatureControl.xaml.cs 26 KB

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