CPDFLineStyleControl.xaml.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using compdfkit_tools.Data;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Drawing.Drawing2D;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Data;
  11. using System.Windows.Documents;
  12. using System.Windows.Input;
  13. using System.Windows.Media;
  14. using System.Windows.Media.Imaging;
  15. using System.Windows.Navigation;
  16. using System.Windows.Shapes;
  17. using DashStyle = System.Windows.Media.DashStyle;
  18. namespace compdfkit_tools.Common
  19. {
  20. /// <summary>
  21. /// CPDFLineStyleControl.xaml 的交互逻辑
  22. /// </summary>
  23. public partial class CPDFLineStyleControl : UserControl
  24. {
  25. public event EventHandler LineStyleChanged;
  26. private DashStyle _dashStyle;
  27. public DashStyle DashStyle
  28. {
  29. get
  30. {
  31. _dashStyle = CalculateDashStyle(CPDFLineStyleUI.DashStyle);
  32. return _dashStyle;
  33. }
  34. set
  35. {
  36. _dashStyle = value;
  37. if(_dashStyle.Dashes.ToArray().Length == 0)
  38. {
  39. CPDFLineStyleUI.SolidRadioButton.IsChecked = true;
  40. }
  41. else
  42. {
  43. CPDFLineStyleUI.DashRadioButton.IsChecked = true;
  44. CPDFLineStyleUI.DashSpacing = (int)(_dashStyle.Dashes.ToArray().First());
  45. }
  46. }
  47. }
  48. public CPDFLineStyleControl()
  49. {
  50. InitializeComponent();
  51. CPDFLineStyleUI.LineStyleChanged += CPDFLineStyleUI_LineStyleChanged;
  52. }
  53. public DashStyle CalculateDashStyle(CPDFDashData pdfDash)
  54. {
  55. DashStyle dashStyle = new DashStyle();
  56. if (pdfDash.IsSolid)
  57. {
  58. dashStyle = DashStyles.Solid;
  59. return dashStyle;
  60. }
  61. else
  62. {
  63. dashStyle.Dashes.Add(pdfDash.DashSpacing);
  64. dashStyle.Dashes.Add(pdfDash.DashSpacing);
  65. return dashStyle;
  66. }
  67. }
  68. private void CPDFLineStyleUI_LineStyleChanged(object sender, EventArgs e)
  69. {
  70. LineStyleChanged?.Invoke(this, EventArgs.Empty);
  71. }
  72. }
  73. }