SignPropertyViewModel.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. using ComPDFKit.PDFAnnotation;
  2. using ComPDFKitViewer.AnnotEvent;
  3. using ComPDFKitViewer.PdfViewer;
  4. using PDF_Master.Helper;
  5. using PDF_Master.Model;
  6. using Prism.Commands;
  7. using Prism.Mvvm;
  8. using Prism.Regions;
  9. using Prism.Services.Dialogs;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. using System.Windows.Media;
  16. namespace PDF_Master.ViewModels.Form
  17. {
  18. public class SignPropertyViewModel : FormBaseVM, INavigationAware
  19. {
  20. #region Command
  21. public DelegateCommand<string> FieldNameTextChangedCommand { get; set; }
  22. public DelegateCommand<string> ToolTipTextChangedCommand { get; set; }
  23. //外观
  24. public DelegateCommand<object> ResetColorCommand { get; set; }
  25. public DelegateCommand<object> ResetColorCheckedBtnCommand { get; set; }
  26. public DelegateCommand<string> ExportedValuesTextChangedCommand { get; set; }
  27. public DelegateCommand<object> LineStyleCommand { get; set; }
  28. #endregion
  29. #region 变量
  30. private CPDFViewer PDFViewer;
  31. private WidgetSignArgs signArgs;
  32. private IDialogService dialogs;
  33. public event EventHandler<int> SelectResetColorBtnHandler;
  34. #endregion
  35. #region 初始化
  36. public SignPropertyViewModel()
  37. {
  38. InitVariable();
  39. InitCommand();
  40. }
  41. private void InitVariable()
  42. {
  43. InitAllResetColor();
  44. }
  45. private void InitAllResetColor()
  46. {
  47. ResetColorOne = InitResetColor(Colors.Transparent, Color.FromArgb(0xFF, 0x00, 0x00, 0x00), Colors.Transparent);
  48. ResetColorTwo = InitResetColor(Color.FromArgb(0xFF, 0x00, 0x00, 0x00), Color.FromArgb(0xFF, 0x00, 0x00, 0x00), Colors.Transparent);
  49. ResetColorThree = InitResetColor(Color.FromArgb(0xFF, 0x00, 0x00, 0x00), Color.FromArgb(0xFF, 0x00, 0x00, 0x00), Colors.Transparent);
  50. ResetColorForth = InitResetColor(Color.FromArgb(0xFF, 0xff, 0x00, 0x00), Color.FromArgb(0xFF, 0xff, 0x00, 0x00), Colors.Transparent);
  51. }
  52. private void InitCommand()
  53. {
  54. //一般
  55. FieldNameTextChangedCommand = new DelegateCommand<string>(FieldNameTextChanged);
  56. ToolTipTextChangedCommand = new DelegateCommand<string>(ToolTipTextChanged);
  57. //外观
  58. ResetColorCheckedBtnCommand = new DelegateCommand<object>(ResetColorCheckedBtn);
  59. ResetColorCommand = new DelegateCommand<object>(ResetColorEvent);
  60. LineStyleCommand = new DelegateCommand<object>(LineStyleBtnEvent);
  61. //选项
  62. ExportedValuesTextChangedCommand = new DelegateCommand<string>(ExportedValuesTextChanged);
  63. }
  64. #endregion
  65. #region 事件
  66. private void FieldNameTextChanged(string obj)
  67. {
  68. if (string.IsNullOrEmpty(obj) == false && IsCurrentWidget == true)
  69. {
  70. FieldName = obj;
  71. }
  72. }
  73. private void ToolTipTextChanged(string obj)
  74. {
  75. if (string.IsNullOrEmpty(obj) == false && IsCurrentWidget == true)
  76. {
  77. ToolTipStr = obj;
  78. }
  79. }
  80. private void LineStyleBtnEvent(object obj)
  81. {
  82. if (obj != null)
  83. {
  84. switch ((string)obj)
  85. {
  86. case "Solid":
  87. BorderStyle = ComPDFKit.PDFAnnotation.C_BORDER_STYLE.BS_SOLID;
  88. break;
  89. case "Dotted":
  90. BorderStyle = ComPDFKit.PDFAnnotation.C_BORDER_STYLE.BS_DASHDED;
  91. break;
  92. }
  93. }
  94. }
  95. private void ExportedValuesTextChanged(string obj)
  96. {
  97. if (obj != null && IsCurrentWidget == true)
  98. {
  99. ExportedValues = obj;
  100. }
  101. }
  102. private void ResetColorCheckedBtn(object obj)
  103. {
  104. if (obj != null)
  105. {
  106. var str = obj as string;
  107. if (str != null)
  108. {
  109. switch (str)
  110. {
  111. case "One":
  112. BorderColor = ResetColorOne.BorderColor.Color;
  113. ContentColor = ResetColorOne.FontColor.Color;
  114. FillColor = ResetColorOne.FillColor.Color;
  115. break;
  116. case "Two":
  117. BorderColor = ResetColorTwo.BorderColor.Color;
  118. ContentColor = ResetColorTwo.FontColor.Color;
  119. FillColor = ResetColorTwo.FillColor.Color;
  120. break;
  121. case "Three":
  122. BorderColor = ResetColorThree.BorderColor.Color;
  123. ContentColor = ResetColorThree.FontColor.Color;
  124. FillColor = ResetColorThree.FillColor.Color;
  125. break;
  126. case "Forth":
  127. BorderColor = ResetColorForth.BorderColor.Color;
  128. ContentColor = ResetColorForth.FontColor.Color;
  129. FillColor = ResetColorForth.FillColor.Color;
  130. break;
  131. }
  132. }
  133. }
  134. }
  135. private void ResetColorEvent(object obj)
  136. {
  137. bool result = true;
  138. DialogParameters value = new DialogParameters();
  139. value.Add(ParameterNames.PDFViewer, PDFViewer);
  140. dialogs.ShowDialog(DialogNames.EditPresetColorsDialog, value, e =>
  141. {
  142. if (e.Result != ButtonResult.OK)
  143. {
  144. result = false;
  145. }
  146. EditPresetColorsDialogViewModel DialogVM = e.Parameters.GetValue<EditPresetColorsDialogViewModel>(ParameterNames.DataModel);
  147. if (DialogVM != null)
  148. {
  149. }
  150. });
  151. if (!result)
  152. {
  153. return;
  154. }
  155. }
  156. #endregion
  157. #region 外部XAML触发事件
  158. private void UpdataSelectResetColorBtn()
  159. {
  160. int result = 0;
  161. if (UpdataSelectResetColor(ResetColorOne))
  162. {
  163. result = 1;
  164. }
  165. else if (UpdataSelectResetColor(ResetColorTwo))
  166. {
  167. result = 2;
  168. }
  169. else if (UpdataSelectResetColor(ResetColorThree))
  170. {
  171. result = 3;
  172. }
  173. else if (UpdataSelectResetColor(ResetColorForth))
  174. {
  175. result = 4;
  176. }
  177. SelectResetColorBtnHandler?.Invoke(null, result);
  178. }
  179. private bool UpdataSelectResetColor(ResetColor reset)
  180. {
  181. if (reset.FillColor.Color == FillColor &&
  182. reset.FontColor.Color == ContentColor &&
  183. reset.BorderColor.Color == BorderColor
  184. )
  185. {
  186. return true;
  187. }
  188. return false;
  189. }
  190. #endregion
  191. #region Navegation
  192. public bool IsNavigationTarget(NavigationContext navigationContext)
  193. {
  194. return true;
  195. }
  196. public void OnNavigatedFrom(NavigationContext navigationContext)
  197. {
  198. signArgs = null;
  199. isCreateWidget = false;
  200. IsCurrentWidget = false;
  201. }
  202. public void OnNavigatedTo(NavigationContext navigationContext)
  203. {
  204. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  205. navigationContext.Parameters.TryGetValue<WidgetSignArgs>("WidgetArgs", out signArgs);
  206. navigationContext.Parameters.TryGetValue<UpdateAttributeHelper>(ParameterNames.AnnotEvent, out AttribEvent);
  207. GetWidgeText();
  208. UpdataSelectResetColorBtn();
  209. }
  210. private void GetWidgeText()
  211. {
  212. if (signArgs == null)
  213. {
  214. PDFViewer.SetMouseMode(MouseModes.FormEditTool);
  215. signArgs = new WidgetSignArgs();
  216. signArgs.LineWidth = 1;
  217. signArgs.LineColor = Colors.Black;
  218. PDFViewer.SetToolParam(signArgs);
  219. isCreateWidget = true;
  220. }
  221. else
  222. {
  223. PDFViewer.SetToolParam(new AnnotHandlerEventArgs());
  224. isCreateWidget = false;
  225. }
  226. GetProperty();
  227. IsCurrentWidget = true;
  228. }
  229. private void GetProperty()
  230. {
  231. if (signArgs != null)
  232. {
  233. IsLocked = signArgs.Locked;
  234. FieldName = signArgs.FieldName;
  235. ToolTipStr = signArgs.Tooltip;
  236. IsReadOnly = signArgs.ReadOnly;
  237. IsRequiredField = signArgs.IsRequired;
  238. FillColor = signArgs.BgColor;
  239. ContentColor = signArgs.FontColor;
  240. BorderColor = signArgs.LineColor;
  241. BorderThiness = signArgs.LineWidth;
  242. BorderStyle = signArgs.BorderStyle;
  243. //ExportedValues = signArgs.ExportValue;
  244. //避免BorderStyle跟上一个值相同,而没触发更改IsSolid属性
  245. if (BorderStyle == C_BORDER_STYLE.BS_SOLID)
  246. IsSolid = true;
  247. else
  248. IsSolid = false;
  249. }
  250. }
  251. #endregion
  252. }
  253. }