CPDFLineStyleControl.xaml.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using ComPDFKit.Controls.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.Controls.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. CPDFLineStyleUI.LineStyleChanged += CPDFLineStyleUI_LineStyleChanged;
  42. }
  43. public DashStyle CalculateDashStyle(CPDFDashData pdfDash)
  44. {
  45. DashStyle dashStyle = new DashStyle();
  46. if (pdfDash.IsSolid)
  47. {
  48. dashStyle = DashStyles.Solid;
  49. return dashStyle;
  50. }
  51. else
  52. {
  53. dashStyle.Dashes.Add(pdfDash.DashSpacing);
  54. dashStyle.Dashes.Add(pdfDash.DashSpacing);
  55. return dashStyle;
  56. }
  57. }
  58. private void CPDFLineStyleUI_LineStyleChanged(object sender, EventArgs e)
  59. {
  60. LineStyleChanged?.Invoke(this, EventArgs.Empty);
  61. }
  62. }
  63. }