AddAnnotationDialogViewModel.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. using ComPDFKit.PDFAnnotation;
  2. using ComPDFKitViewer;
  3. using ComPDFKitViewer.AnnotEvent;
  4. using Microsoft.Office.Interop.Word;
  5. using PDF_Office.Helper;
  6. using PDF_Office.Model;
  7. using PDF_Office.Model.BOTA;
  8. using Prism.Commands;
  9. using Prism.Mvvm;
  10. using Prism.Regions;
  11. using Prism.Services.Dialogs;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Linq;
  15. using System.Text;
  16. using System.Threading.Tasks;
  17. using System.Windows;
  18. using System.Windows.Annotations;
  19. using System.Windows.Controls;
  20. using System.Windows.Markup;
  21. using System.Windows.Media;
  22. namespace PDF_Office.ViewModels.Dialog.BOTA
  23. {
  24. public class AddAnnotationDialogViewModel : BindableBase, IDialogAware
  25. {
  26. private string title;
  27. public string Title
  28. {
  29. get { return title; }
  30. set { SetProperty(ref title, value); }
  31. }
  32. public event Action<IDialogResult> RequestClose;
  33. private string markupContent;
  34. public string MarkupContent
  35. {
  36. get { return markupContent; }
  37. set
  38. {
  39. SetProperty(ref markupContent, value);
  40. }
  41. }
  42. private string annotationName;
  43. public string AnnotationName
  44. {
  45. get { return annotationName; }
  46. set
  47. {
  48. SetProperty(ref annotationName, value);
  49. }
  50. }
  51. public AnnotationHandlerEventArgs Annotation { get; set; }
  52. public AnnotAttribEvent AnnotEvent { get; set; }
  53. public DelegateCommand CreateCommnad { get; set; }
  54. public DelegateCommand CancelCommand { get; set; }
  55. public DelegateCommand<Object> LostFocusCommand { get; set; }
  56. public AddAnnotationDialogViewModel()
  57. {
  58. CancelCommand = new DelegateCommand(CancelEvent);
  59. CreateCommnad = new DelegateCommand(CreateEvent);
  60. LostFocusCommand = new DelegateCommand<object>(LostFocusEvent);
  61. }
  62. private void LostFocusEvent(object obj)
  63. {
  64. if (obj is CompositeCommandParameter composite)
  65. {
  66. if (composite.Parameter is TextBox textBox)
  67. {
  68. Annotation.MarkupContent = textBox.Text;
  69. Annotation.AnnotHandlerEventArgs.MarkupContent = textBox.Text;
  70. }
  71. }
  72. }
  73. private void CreateEvent()
  74. {
  75. DialogParameters valuePairs = new DialogParameters();
  76. valuePairs.Add(ParameterNames.Annotation, Annotation);
  77. valuePairs.Add(ParameterNames.AnnotEvent, AnnotEvent);
  78. RequestClose.Invoke(new DialogResult(ButtonResult.OK, valuePairs));
  79. }
  80. private void CancelEvent()
  81. {
  82. RequestClose.Invoke(new DialogResult(ButtonResult.Cancel));
  83. }
  84. public bool CanCloseDialog()
  85. {
  86. return true;
  87. }
  88. public void OnDialogClosed()
  89. {
  90. }
  91. public void OnDialogOpened(IDialogParameters parameters)
  92. {
  93. AnnotationHandlerEventArgs annotation;
  94. parameters.TryGetValue<AnnotationHandlerEventArgs>(ParameterNames.Annotation, out annotation);
  95. string title = "1";
  96. if (annotation != null)
  97. {
  98. Annotation = annotation;
  99. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  100. switch (annotation.EventType)
  101. {
  102. case AnnotArgsType.AnnotFreeText://文本
  103. title = "文本";
  104. //FreeTextAnnotArgs freetextArgs = annotation.AnnotHandlerEventArgs as FreeTextAnnotArgs; ;
  105. //annotAttribsList[AnnotAttrib.Color] = freetextArgs.LineColor;
  106. //annotAttribsList[AnnotAttrib.FillColor] = freetextArgs.BgColor;
  107. //annotAttribsList[AnnotAttrib.Thickness] = freetextArgs.LineWidth;
  108. //annotAttribsList[AnnotAttrib.Transparency] = freetextArgs.Transparency;
  109. //annotAttribsList[AnnotAttrib.FontColor] = freetextArgs.FontColor;
  110. //annotAttribsList[AnnotAttrib.FontSize] = freetextArgs.FontSize;
  111. //annotAttribsList[AnnotAttrib.FontFamily] = freetextArgs.FontFamily;
  112. //annotAttribsList[AnnotAttrib.FontStyle] = freetextArgs.FontStyle;
  113. //annotAttribsList[AnnotAttrib.FontWeight] = freetextArgs.FontWeight;
  114. //annotAttribsList[AnnotAttrib.TextAlign] = TextAlignment.Left;
  115. //annotAttribsList[AnnotAttrib.NoteText] = freetextArgs.TextContent;
  116. //AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(freetextArgs, annotAttribsList);
  117. break;
  118. case AnnotArgsType.AnnotHighlight:
  119. title = "高亮";
  120. break;
  121. case AnnotArgsType.AnnotFreehand:
  122. title = "手绘";
  123. break;
  124. case AnnotArgsType.AnnotSquiggly://波浪线
  125. title = "波浪线";
  126. break;
  127. case AnnotArgsType.AnnotStamp:
  128. title = "图章";
  129. break;
  130. case AnnotArgsType.AnnotStrikeout://删除线
  131. title = "删除线";
  132. break;
  133. case AnnotArgsType.AnnotSticky://便签
  134. break;
  135. case AnnotArgsType.AnnotUnderline:
  136. title = "下划线";
  137. break;
  138. case AnnotArgsType.AnnotLine:
  139. if ((annotation.AnnotHandlerEventArgs as LineAnnotArgs).HeadLineType >= (C_LINE_TYPE)1 || (annotation.AnnotHandlerEventArgs as LineAnnotArgs).TailLineType >= (C_LINE_TYPE)1)
  140. {
  141. title = "箭头";
  142. }
  143. else
  144. {
  145. title = "线";
  146. }
  147. break;
  148. case AnnotArgsType.AnnotSquare:
  149. title = "矩形";
  150. break;
  151. case AnnotArgsType.AnnotCircle:
  152. title = "圆";
  153. break;
  154. }
  155. if (!string.IsNullOrEmpty(annotation.MarkupContent))
  156. {
  157. title = title + "-" + annotation.MarkupContent;
  158. }
  159. Title = title;
  160. MarkupContent = annotation.MarkupContent;
  161. AnnotationName = "页面" + (annotation.PageIndex + 1).ToString();
  162. return;
  163. }
  164. }
  165. }
  166. }