AddAnnotationDialogViewModel.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. using ComPDFKit.PDFAnnotation;
  2. using ComPDFKitViewer;
  3. using ComPDFKitViewer.AnnotEvent;
  4. using DryIoc;
  5. using Microsoft.Office.Interop.Word;
  6. using PDF_Office.Helper;
  7. using PDF_Office.Model;
  8. using PDF_Office.Model.BOTA;
  9. using Prism.Commands;
  10. using Prism.Mvvm;
  11. using Prism.Regions;
  12. using Prism.Services.Dialogs;
  13. using System;
  14. using System.Collections.Generic;
  15. using System.Linq;
  16. using System.Text;
  17. using System.Threading.Tasks;
  18. using System.Windows;
  19. using System.Windows.Annotations;
  20. using System.Windows.Controls;
  21. using System.Windows.Markup;
  22. using System.Windows.Media;
  23. namespace PDF_Office.ViewModels.Dialog.BOTA
  24. {
  25. public class AddAnnotationDialogViewModel : BindableBase, IDialogAware
  26. {
  27. private string title = "添加笔记";
  28. public string Title
  29. {
  30. get { return title; }
  31. set { SetProperty(ref title, value); }
  32. }
  33. public event Action<IDialogResult> RequestClose;
  34. //private string markupContent;
  35. //public string MarkupContent
  36. //{
  37. // get { return markupContent; }
  38. // set
  39. // {
  40. // SetProperty(ref markupContent, value);
  41. // }
  42. //}
  43. private string contentText;
  44. public string ContentText
  45. {
  46. get { return contentText; }
  47. set
  48. {
  49. SetProperty(ref contentText, value);
  50. }
  51. }
  52. private string annotationName;
  53. public string AnnotationName
  54. {
  55. get { return annotationName; }
  56. set
  57. {
  58. SetProperty(ref annotationName, value);
  59. }
  60. }
  61. private Visibility tipVisibility;
  62. public Visibility TipVisibility
  63. {
  64. get { return tipVisibility; }
  65. set
  66. {
  67. SetProperty(ref tipVisibility, value);
  68. }
  69. }
  70. public AnnotationHandlerEventArgs Annotation { get; set; }
  71. public AnnotAttribEvent AnnotEvent { get; set; }
  72. public DelegateCommand CreateCommnad { get; set; }
  73. public DelegateCommand CancelCommand { get; set; }
  74. public DelegateCommand<Object> LostFocusCommand { get; set; }
  75. public AddAnnotationDialogViewModel()
  76. {
  77. CancelCommand = new DelegateCommand(CancelEvent);
  78. CreateCommnad = new DelegateCommand(CreateEvent);
  79. LostFocusCommand = new DelegateCommand<object>(LostFocusEvent);
  80. }
  81. private void LostFocusEvent(object obj)
  82. {
  83. if (obj is CompositeCommandParameter composite)
  84. {
  85. if (composite.Parameter is TextBox textBox)
  86. {
  87. Annotation.Content = textBox.Text;
  88. AnnotEvent?.UpdateAttrib(AnnotAttrib.NoteText, textBox.Text);
  89. AnnotEvent?.UpdateAnnot();
  90. }
  91. }
  92. }
  93. private void CreateEvent()
  94. {
  95. DialogParameters valuePairs = new DialogParameters();
  96. valuePairs.Add(ParameterNames.Annotation, Annotation);
  97. valuePairs.Add(ParameterNames.AnnotEvent, AnnotEvent);
  98. RequestClose.Invoke(new DialogResult(ButtonResult.OK, valuePairs));
  99. }
  100. private void CancelEvent()
  101. {
  102. RequestClose.Invoke(new DialogResult(ButtonResult.Cancel));
  103. }
  104. public bool CanCloseDialog()
  105. {
  106. return true;
  107. }
  108. public void OnDialogClosed()
  109. {
  110. }
  111. public void OnDialogOpened(IDialogParameters parameters)
  112. {
  113. AnnotationHandlerEventArgs annotation;
  114. parameters.TryGetValue<AnnotationHandlerEventArgs>(ParameterNames.Annotation, out annotation);
  115. if (annotation != null)
  116. {
  117. Annotation = annotation;
  118. Dictionary<AnnotAttrib, object> annotAttribsList = annotation.AnnotHandlerEventArgs.GetAnnotAttrib();
  119. AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annotation.AnnotHandlerEventArgs, annotAttribsList);
  120. ContentText = annotation.Content;
  121. AnnotationName = "页面" + (annotation.PageIndex + 1).ToString();
  122. if (string.IsNullOrEmpty(ContentText))
  123. {
  124. TipVisibility = Visibility.Visible;
  125. }
  126. else
  127. {
  128. TipVisibility = Visibility.Collapsed;
  129. }
  130. return;
  131. }
  132. }
  133. }
  134. }