FreehandAnnotPropertyViewModel.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. using ComPDFKitViewer.AnnotEvent;
  2. using PDF_Office.Model;
  3. using PDF_Office.ViewModels.Tools;
  4. using Prism.Commands;
  5. using Prism.Mvvm;
  6. using Prism.Regions;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows.Controls.Primitives;
  13. using System.Windows.Media;
  14. namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
  15. {
  16. public class FreehandAnnotPropertyViewModel : BindableBase, INavigationAware
  17. {
  18. private Brush selectColor = new SolidColorBrush(Colors.Transparent);
  19. public Brush SelectColor
  20. {
  21. get { return selectColor; }
  22. set { SetProperty(ref selectColor, value); SetAnnotProperty(); }
  23. }
  24. private double annotOpacity = 1;
  25. public double AnnotOpacity
  26. {
  27. get { return annotOpacity; }
  28. set
  29. {
  30. SetProperty(ref annotOpacity, value);
  31. }
  32. }
  33. private double thicknessLine = 1;
  34. public double ThicknessLine
  35. {
  36. get { return thicknessLine; }
  37. set
  38. {
  39. SetProperty(ref thicknessLine, value); SetAnnotProperty();
  40. }
  41. }
  42. private FreehandAnnotArgs Annot;
  43. private AnnotPropertyPanel PropertyPanel;
  44. public DelegateCommand<object> EraseCommand { get; set; }
  45. public DelegateCommand<object> PenCommand { get; set; }
  46. public DelegateCommand<object> SelectedColorChangedCommand { get; set; }
  47. public DelegateCommand<object> SelectedValueChangedCommand { get; set; }
  48. public FreehandAnnotPropertyViewModel()
  49. {
  50. EraseCommand = new DelegateCommand<object>(Erase_Command);
  51. PenCommand = new DelegateCommand<object>(Pen_Command);
  52. SelectedColorChangedCommand = new DelegateCommand<object>(SelectedColorChanged_Click);
  53. SelectedValueChangedCommand = new DelegateCommand<object>(SelectedValueChanged_Command);
  54. }
  55. private void SelectedValueChanged_Command(object obj)
  56. {
  57. if (obj != null)
  58. {
  59. annotOpacity = (double)obj;
  60. SelectColor.Opacity = annotOpacity;
  61. SetAnnotProperty();
  62. Dictionary<AnnotArgsType, object> changeData = new Dictionary<AnnotArgsType, object>();
  63. changeData[AnnotArgsType.AnnotFreehand] = annotOpacity;
  64. PropertyPanel.DataChangedInvoke(this, changeData);
  65. }
  66. }
  67. private void SelectedColorChanged_Click(object obj)
  68. {
  69. if (obj != null)
  70. {
  71. var colorValue = (Color)obj;
  72. if (colorValue != null)
  73. {
  74. SelectColor = new SolidColorBrush(colorValue);
  75. SelectColor.Opacity = AnnotOpacity;
  76. Dictionary<AnnotArgsType, object> changeData = new Dictionary<AnnotArgsType, object>();
  77. changeData[AnnotArgsType.AnnotFreehand] = obj;
  78. PropertyPanel.DataChangedInvoke(this, changeData);
  79. }
  80. }
  81. }
  82. private void Erase_Command(object obj)
  83. {
  84. var btn = obj as ToggleButton;
  85. if(btn.IsChecked == true)
  86. {
  87. Dictionary<AnnotArgsType, object> changeData = new Dictionary<AnnotArgsType, object>();
  88. changeData[AnnotArgsType.AnnotErase] = btn;
  89. PropertyPanel.DataChangedInvoke(this, changeData);
  90. }
  91. }
  92. private void Pen_Command(object obj)
  93. {
  94. var btn = obj as ToggleButton;
  95. if (btn.IsChecked == true)
  96. {
  97. Dictionary<AnnotArgsType, object> changeData = new Dictionary<AnnotArgsType, object>();
  98. changeData[AnnotArgsType.AnnotErase] = btn;
  99. PropertyPanel.DataChangedInvoke(this, changeData);
  100. }
  101. }
  102. public bool IsNavigationTarget(NavigationContext navigationContext)
  103. {
  104. return true;
  105. }
  106. public void OnNavigatedFrom(NavigationContext navigationContext)
  107. {
  108. }
  109. public void OnNavigatedTo(NavigationContext navigationContext)
  110. {
  111. navigationContext.Parameters.TryGetValue<AnnotPropertyPanel>(ParameterNames.PropertyPanelContentViewModel, out PropertyPanel);
  112. if (PropertyPanel != null)
  113. {
  114. Annot = PropertyPanel.annot as FreehandAnnotArgs;
  115. }
  116. }
  117. private void SetAnnotProperty()
  118. {
  119. if (Annot != null)
  120. {
  121. if (Annot is FreehandAnnotArgs)
  122. {
  123. if (Annot.Transparency != AnnotOpacity)
  124. Annot.Transparency = AnnotOpacity;
  125. if (Annot.LineWidth != ThicknessLine)
  126. Annot.LineWidth = ThicknessLine;
  127. var c = (SelectColor as SolidColorBrush).Color;
  128. if (Annot.InkColor.A != c.A || Annot.InkColor.B != c.B || Annot.InkColor.G != c.G || Annot.InkColor.R != c.R)
  129. Annot.InkColor = (SelectColor as SolidColorBrush).Color;
  130. }
  131. }
  132. }
  133. }
  134. }