DashBorder.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using ComPDFKitViewer.Annot;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Data;
  10. using System.Windows.Media;
  11. using System.Windows.Shapes;
  12. namespace ComPDFKit.Tool.DrawTool
  13. {
  14. internal class DashedBorder : Border
  15. {
  16. private bool DrawDash { get; set; }
  17. private double DashThickness { get; set; }
  18. private double DashWidth { get; set; }
  19. private DoubleCollection DashArray { get; set; }
  20. protected override void OnRender(DrawingContext dc)
  21. {
  22. if (DrawDash)
  23. {
  24. Pen dashPen = new Pen(BorderBrush, DashThickness);
  25. dashPen.DashCap = PenLineCap.Flat;
  26. DashStyle dash = new DashStyle();
  27. foreach (double offset in DashArray)
  28. {
  29. dash.Dashes.Add(offset / DashWidth);
  30. }
  31. dashPen.DashStyle = dash;
  32. dc.DrawRectangle(null, dashPen, new Rect(0, 0, ActualWidth, ActualHeight));
  33. return;
  34. }
  35. base.OnRender(dc);
  36. }
  37. public void DrawDashBorder(bool isDash,double dashWidth,double rawWidth, DoubleCollection dashArray)
  38. {
  39. DrawDash = isDash;
  40. DashArray = dashArray;
  41. DashThickness=dashWidth;
  42. DashWidth=rawWidth;
  43. InvalidateVisual();
  44. }
  45. }
  46. }