SignPropertyViewModel.cs 9.5 KB

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