SharpsAnnotProperty.xaml.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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.SetSelectedColor(annot.LineColor);
  48. cusFillColor.SetSelectedColor(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.SetSelectedColor(annot.LineColor);
  61. cusFillColor.SetSelectedColor(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.SetSelectedColor(annot.LineColor);
  74. cusFillColor.SetSelectedColor(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. BtnSolidLine.IsChecked = true;
  91. BtnDottedLine.IsChecked = false;
  92. }
  93. else
  94. {
  95. BtnDottedLine.IsChecked = true;
  96. BtnSolidLine.IsChecked = false;
  97. }
  98. }
  99. private void layerFill_SelectedValue(object sender, double e)
  100. {
  101. if (ViewModel != null)
  102. {
  103. ViewModel.SelectedFillOpacityCommand?.Execute(e);
  104. }
  105. }
  106. private void cusFillColor_SelectedColor(object sender, Color e)
  107. {
  108. if (ViewModel != null)
  109. {
  110. ViewModel.SelectedFillColorCommand?.Execute(e);
  111. }
  112. }
  113. private void layerThick_SelectedValue(object sender, double e)
  114. {
  115. if (ViewModel != null)
  116. {
  117. ViewModel.SelectedThickCommand?.Execute(e);
  118. }
  119. }
  120. private void cusColor_SelectedColor(object sender, Color e)
  121. {
  122. if (ViewModel != null)
  123. {
  124. ViewModel.SelectedColorCommand?.Execute(e);
  125. }
  126. }
  127. private void SharpsBtn_Click(object sender, RoutedEventArgs e)
  128. {
  129. var btn = sender as ToggleButton;
  130. foreach(var item in ToolGrid.Children)
  131. {
  132. var btnItem = item as ToggleButton;
  133. if(btnItem != null)
  134. {
  135. if(btnItem != btn)
  136. {
  137. btnItem.IsChecked = false;
  138. }
  139. else
  140. {
  141. btnItem.IsChecked = true;
  142. if(btnItem.Tag.ToString() == "Arrow" || btnItem.Tag.ToString() == "Line")
  143. {
  144. GridFill.Visibility = Visibility.Collapsed;
  145. }
  146. else
  147. {
  148. GridFill.Visibility = Visibility.Visible;
  149. }
  150. }
  151. }
  152. }
  153. }
  154. private void BtnLineStyle_Click(object sender, RoutedEventArgs e)
  155. {
  156. var btn = sender as CustomIconToggleBtn;
  157. foreach (var item in PnlLineStyle.Children)
  158. {
  159. var btnItem = item as CustomIconToggleBtn;
  160. if (btnItem != null)
  161. {
  162. if (btnItem != btn)
  163. {
  164. btnItem.IsChecked = false;
  165. }
  166. else
  167. {
  168. btnItem.IsChecked = true;
  169. }
  170. }
  171. }
  172. }
  173. }
  174. }