SignatureAnnotPropertyViewModel.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. using ComPDFKitViewer.AnnotEvent;
  2. using ComPDFKitViewer.PdfViewer;
  3. using PDF_Office.Model;
  4. using PDF_Office.Model.AnnotPanel;
  5. using Prism.Commands;
  6. using Prism.Mvvm;
  7. using Prism.Regions;
  8. using Prism.Services.Dialogs;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Collections.ObjectModel;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
  16. {
  17. class SignatureAnnotPropertyViewModel : BindableBase, INavigationAware
  18. {
  19. private CPDFViewer PDFViewer;
  20. private IDialogService dialogs;
  21. public DelegateCommand ShowDialogCommand { get; set; }
  22. public ObservableCollection<Signature> SignatureList { get; set; }
  23. public SignatureAnnotPropertyViewModel(IDialogService dialogService)
  24. {
  25. dialogs = dialogService;
  26. ShowDialogCommand = new DelegateCommand(ShowDialog);
  27. SignatureList = new ObservableCollection<Signature>();
  28. }
  29. public void SetSignature(Signature signature)
  30. {
  31. switch (signature.Type)
  32. {
  33. case SignatureType.TextType:
  34. case SignatureType.ImageType:
  35. StampAnnotArgs stampArgs = new StampAnnotArgs();
  36. stampArgs.Opacity = 1;
  37. stampArgs.Type = StampType.IMAGE_STAMP;
  38. stampArgs.ImagePath = signature.SourcePath;
  39. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  40. PDFViewer.SetToolParam(stampArgs);
  41. break;
  42. case SignatureType.Drawing:
  43. break;
  44. default:
  45. break;
  46. }
  47. }
  48. private void ShowDialog()
  49. {
  50. bool result = true;
  51. DialogParameters value = new DialogParameters();
  52. value.Add(ParameterNames.PDFViewer, PDFViewer);
  53. dialogs.ShowDialog(DialogNames.SignatureCreateDialog, value, e =>
  54. {
  55. if (e.Result != ButtonResult.OK)
  56. {
  57. result = false;
  58. }
  59. SignatureCreateDialogViewModel DialogVM = e.Parameters.GetValue<SignatureCreateDialogViewModel>(ParameterNames.DataModel);
  60. if (DialogVM != null)
  61. {
  62. CreateSignature(DialogVM);
  63. }
  64. });
  65. if (!result)
  66. {
  67. return;
  68. }
  69. }
  70. /// <summary>
  71. /// 创建签名,并保存到APP缓存
  72. /// </summary>
  73. /// <param name="viewModel"></param>
  74. private void CreateSignature(SignatureCreateDialogViewModel viewModel)
  75. {
  76. Signature Signature = new Signature();
  77. Signature.SourcePath = viewModel.SaveToPath;
  78. Signature.Type = (SignatureType)viewModel.TabItemIndex;
  79. SignatureList.Add(Signature);
  80. }
  81. public bool IsNavigationTarget(NavigationContext navigationContext)
  82. {
  83. return true;
  84. }
  85. public void OnNavigatedFrom(NavigationContext navigationContext)
  86. {
  87. return;
  88. }
  89. public void OnNavigatedTo(NavigationContext navigationContext)
  90. {
  91. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  92. if (PDFViewer == null)
  93. {
  94. return;
  95. }
  96. }
  97. }
  98. }