CPDFMarkupUI.xaml.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using compdfkit_tools.Data;
  2. using ComPDFKitViewer.AnnotEvent;
  3. using ComPDFKitViewer.PdfViewer;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10. using System.Windows.Controls;
  11. using System.Windows.Data;
  12. using System.Windows.Documents;
  13. using System.Windows.Input;
  14. using System.Windows.Media;
  15. using System.Windows.Media.Imaging;
  16. using System.Windows.Navigation;
  17. using System.Windows.Shapes;
  18. namespace compdfkit_tools.PDFControlUI
  19. {
  20. /// <summary>
  21. /// CPDFMarkupUI.xaml 的交互逻辑
  22. /// </summary>
  23. public partial class CPDFMarkupUI : UserControl
  24. {
  25. private AnnotationType currentAnnotationType;
  26. public event EventHandler<CPDFAnnotationData> PropertyChanged;
  27. public CPDFMarkupUI()
  28. {
  29. InitializeComponent();
  30. ColorPickerControl.ColorChanged += ColorPickerControl_ColorChanged;
  31. CPDFOpacityControl.OpacityChanged += CPDFOpacityControl_OpacityChanged;
  32. }
  33. private void CPDFOpacityControl_OpacityChanged(object sender, EventArgs e)
  34. {
  35. PropertyChanged?.Invoke(this, GetMarkupData());
  36. }
  37. private void ColorPickerControl_ColorChanged(object sender, EventArgs e)
  38. {
  39. PropertyChanged?.Invoke(this, GetMarkupData());
  40. }
  41. private void NoteTextBox_TextChanged(object sender, TextChangedEventArgs e)
  42. {
  43. PropertyChanged?.Invoke(this, GetMarkupData());
  44. }
  45. public CPDFMarkupData GetMarkupData()
  46. {
  47. CPDFMarkupData pdfMarkupData = new CPDFMarkupData();
  48. pdfMarkupData.AnnotationType = currentAnnotationType;
  49. pdfMarkupData.Color = ((SolidColorBrush)ColorPickerControl.Brush).Color;
  50. pdfMarkupData.Opacity = CPDFOpacityControl.OpacityValue / 100.0;
  51. pdfMarkupData.Note = NoteTextBox.Text;
  52. return pdfMarkupData;
  53. }
  54. public void InitWithAnnotationType(AnnotationType annotationType)
  55. {
  56. switch (annotationType)
  57. {
  58. case AnnotationType.Highlight:
  59. TitleTextBlock.Text = "Highlight";
  60. break;
  61. case AnnotationType.Underline:
  62. TitleTextBlock.Text = "Underline";
  63. break;
  64. case AnnotationType.Strikeout:
  65. TitleTextBlock.Text = "Strikeout";
  66. break;
  67. case AnnotationType.Squiggly:
  68. TitleTextBlock.Text = "Squiggly";
  69. break;
  70. default:
  71. throw new ArgumentException("Not Excepted Argument");
  72. }
  73. currentAnnotationType = annotationType;
  74. }
  75. }
  76. }