CPDFLineStyleControl.xaml.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using Compdfkit_Tools.Data;
  2. using System;
  3. using System.Linq;
  4. using System.Windows.Controls;
  5. using System.Windows.Media;
  6. using DashStyle = System.Windows.Media.DashStyle;
  7. namespace Compdfkit_Tools.Common
  8. {
  9. public partial class CPDFLineStyleControl : UserControl
  10. {
  11. public event EventHandler LineStyleChanged;
  12. private DashStyle _dashStyle;
  13. public DashStyle DashStyle
  14. {
  15. get
  16. {
  17. _dashStyle = CalculateDashStyle(CPDFLineStyleUI.DashStyle);
  18. return _dashStyle;
  19. }
  20. set
  21. {
  22. _dashStyle = value;
  23. if(_dashStyle.Dashes.ToArray().Length == 0)
  24. {
  25. CPDFLineStyleUI.SolidRadioButton.IsChecked = true;
  26. CPDFLineStyleUI.IsSolid = true;
  27. CPDFLineStyleUI.DashSpacing = 1;
  28. }
  29. else
  30. {
  31. CPDFLineStyleUI.DashRadioButton.IsChecked = true;
  32. CPDFLineStyleUI.IsSolid = false;
  33. CPDFLineStyleUI.DashSpacing = (int)(_dashStyle.Dashes.ToArray().First());
  34. }
  35. }
  36. }
  37. public CPDFLineStyleControl()
  38. {
  39. InitializeComponent();
  40. CPDFLineStyleUI.LineStyleChanged += CPDFLineStyleUI_LineStyleChanged;
  41. }
  42. public DashStyle CalculateDashStyle(CPDFDashData pdfDash)
  43. {
  44. DashStyle dashStyle = new DashStyle();
  45. if (pdfDash.IsSolid)
  46. {
  47. dashStyle = DashStyles.Solid;
  48. return dashStyle;
  49. }
  50. else
  51. {
  52. dashStyle.Dashes.Add(pdfDash.DashSpacing);
  53. dashStyle.Dashes.Add(pdfDash.DashSpacing);
  54. return dashStyle;
  55. }
  56. }
  57. private void CPDFLineStyleUI_LineStyleChanged(object sender, EventArgs e)
  58. {
  59. LineStyleChanged?.Invoke(this, EventArgs.Empty);
  60. }
  61. }
  62. }