SharpsAnnotProperty.xaml.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. using ComPDFKit.PDFAnnotation;
  2. using ComPDFKitViewer.AnnotEvent;
  3. using PDF_Office.CustomControl;
  4. using PDF_Office.ViewModels.PropertyPanel.AnnotPanel;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows;
  11. using System.Windows.Controls;
  12. using System.Windows.Controls.Primitives;
  13. using System.Windows.Data;
  14. using System.Windows.Documents;
  15. using System.Windows.Input;
  16. using System.Windows.Media;
  17. using System.Windows.Media.Imaging;
  18. using System.Windows.Navigation;
  19. using System.Windows.Shapes;
  20. namespace PDF_Office.Views.PropertyPanel.AnnotPanel
  21. {
  22. /// <summary>
  23. /// SharpsAnnotProperty.xaml 的交互逻辑
  24. /// </summary>
  25. public partial class SharpsAnnotProperty : UserControl
  26. {
  27. private SharpsAnnotPropertyViewModel ViewModel => DataContext as SharpsAnnotPropertyViewModel;
  28. public SharpsAnnotProperty()
  29. {
  30. InitializeComponent();
  31. cusColor.SelectedColorHandler += cusColor_SelectedColor;
  32. layerThick.SelectedValueChanged += layerThick_SelectedValue;
  33. cusFillColor.SelectedColorHandler += cusFillColor_SelectedColor;
  34. layerFill.SelectedValueChanged += layerFill_SelectedValue;
  35. ViewModel.LoadPropertyHandler += ViewModel_LoadPropertyHandler;
  36. }
  37. private void ViewModel_LoadPropertyHandler(object sender, object e)
  38. {
  39. var item = e as AnnotHandlerEventArgs;
  40. switch (item.EventType)
  41. {
  42. case AnnotArgsType.AnnotSquare:
  43. {
  44. var annot = item as SquareAnnotArgs;
  45. if (annot != null)
  46. {
  47. cusColor.SelectedColor = annot.LineColor;
  48. cusFillColor.SelectedColor= annot.BgColor;
  49. layerFill.SetSliOpacity(annot.Transparency);
  50. SharpsBtn_Click(SharpRectBtn, null);
  51. SolidLineIschecked(annot.LineDash.Dashes == null || annot.LineDash.Dashes.Count == 0 || annot.LineDash.Dashes[0] == 0);
  52. }
  53. break;
  54. }
  55. case AnnotArgsType.AnnotCircle:
  56. {
  57. var annot = item as CircleAnnotArgs;
  58. if (annot != null)
  59. {
  60. cusColor.SelectedColor=annot.LineColor;
  61. cusFillColor.SelectedColor=annot.BgColor;
  62. layerFill.SetSliOpacity(annot.Transparency);
  63. SharpsBtn_Click(SharpCircleBtn, null);
  64. SolidLineIschecked(annot.LineDash.Dashes == null || annot.LineDash.Dashes.Count == 0 || annot.LineDash.Dashes[0] == 0);
  65. }
  66. break;
  67. }
  68. case AnnotArgsType.AnnotLine:
  69. {
  70. var annot = item as LineAnnotArgs;
  71. if (annot != null)
  72. {
  73. cusColor.SelectedColor=annot.LineColor;
  74. cusFillColor.SelectedColor=annot.LineColor;
  75. layerFill.SetSliOpacity(annot.Transparency);
  76. if (annot.TailLineType == C_LINE_TYPE.LINETYPE_ARROW && annot.HeadLineType == C_LINE_TYPE.LINETYPE_NONE)
  77. SharpsBtn_Click(SharpArrowBtn, null);
  78. else
  79. SharpsBtn_Click(SharpLineBtn, null);
  80. SolidLineIschecked(annot.LineDash.Dashes == null || annot.LineDash.Dashes.Count == 0 || annot.LineDash.Dashes[0] == 0);
  81. }
  82. break;
  83. }
  84. }
  85. }
  86. private void SolidLineIschecked(bool isSolid)
  87. {
  88. if (isSolid)
  89. {
  90. BtnSolid.IsChecked = true;
  91. }
  92. else
  93. {
  94. BtnDashed.IsChecked = true;
  95. }
  96. }
  97. private void layerFill_SelectedValue(object sender, double e)
  98. {
  99. if (ViewModel != null)
  100. {
  101. ViewModel.SelectedFillOpacityCommand?.Execute(e);
  102. }
  103. }
  104. private void cusFillColor_SelectedColor(object sender, Color e)
  105. {
  106. if (ViewModel != null)
  107. {
  108. ViewModel.SelectedFillColorCommand?.Execute(e);
  109. }
  110. }
  111. private void layerThick_SelectedValue(object sender, double e)
  112. {
  113. if (ViewModel != null)
  114. {
  115. ViewModel.SelectedThickCommand?.Execute(e);
  116. }
  117. }
  118. private void cusColor_SelectedColor(object sender, Color e)
  119. {
  120. if (ViewModel != null)
  121. {
  122. ViewModel.SelectedColorCommand?.Execute(e);
  123. }
  124. }
  125. private void SharpsBtn_Click(object sender, RoutedEventArgs e)
  126. {
  127. var btn = sender as ToggleButton;
  128. foreach(var item in ToolGrid.Children)
  129. {
  130. var btnItem = item as ToggleButton;
  131. if(btnItem != null)
  132. {
  133. if(btnItem != btn)
  134. {
  135. btnItem.IsChecked = false;
  136. }
  137. else
  138. {
  139. btnItem.IsChecked = true;
  140. if(btnItem.Tag.ToString() == "Arrow" || btnItem.Tag.ToString() == "Line")
  141. {
  142. GridFill.Visibility = Visibility.Collapsed;
  143. }
  144. else
  145. {
  146. GridFill.Visibility = Visibility.Visible;
  147. }
  148. }
  149. }
  150. }
  151. }
  152. private void BtnLineStyle_Click(object sender, RoutedEventArgs e)
  153. {
  154. var btn = sender as CustomIconToggleBtn;
  155. foreach (var item in PnlLineStyle.Children)
  156. {
  157. var btnItem = item as CustomIconToggleBtn;
  158. if (btnItem != null)
  159. {
  160. if (btnItem != btn)
  161. {
  162. btnItem.IsChecked = false;
  163. }
  164. else
  165. {
  166. btnItem.IsChecked = true;
  167. }
  168. }
  169. }
  170. }
  171. }
  172. }