CPDFLineStyleControl.xaml.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. CPDFLineStyleUI.IsSolid = true;
  41. CPDFLineStyleUI.DashSpacing = 1;
  42. }
  43. else
  44. {
  45. CPDFLineStyleUI.DashRadioButton.IsChecked = true;
  46. CPDFLineStyleUI.IsSolid = false;
  47. CPDFLineStyleUI.DashSpacing = (int)(_dashStyle.Dashes.ToArray().First());
  48. }
  49. }
  50. }
  51. public CPDFLineStyleControl()
  52. {
  53. InitializeComponent();
  54. CPDFLineStyleUI.LineStyleChanged += CPDFLineStyleUI_LineStyleChanged;
  55. }
  56. public DashStyle CalculateDashStyle(CPDFDashData pdfDash)
  57. {
  58. DashStyle dashStyle = new DashStyle();
  59. if (pdfDash.IsSolid)
  60. {
  61. dashStyle = DashStyles.Solid;
  62. return dashStyle;
  63. }
  64. else
  65. {
  66. dashStyle.Dashes.Add(pdfDash.DashSpacing);
  67. dashStyle.Dashes.Add(pdfDash.DashSpacing);
  68. return dashStyle;
  69. }
  70. }
  71. private void CPDFLineStyleUI_LineStyleChanged(object sender, EventArgs e)
  72. {
  73. LineStyleChanged?.Invoke(this, EventArgs.Empty);
  74. }
  75. }
  76. }