ArrowLine.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. //------------------------------------------
  2. // ArrowLine.cs (c) 2007 by Charles Petzold
  3. //------------------------------------------
  4. using System.Windows;
  5. using System.Windows.Media;
  6. namespace GraphDrawer
  7. {
  8. public class ArrowLine : ArrowLineBase
  9. {
  10. /// <summary>
  11. /// Identifies the X1 dependency property.
  12. /// </summary>
  13. public static readonly DependencyProperty X1Property =
  14. DependencyProperty.Register("X1",
  15. typeof(double), typeof(ArrowLine),
  16. new FrameworkPropertyMetadata(0.0,
  17. FrameworkPropertyMetadataOptions.AffectsMeasure));
  18. /// <summary>
  19. /// Gets or sets the x-coordinate of the ArrowLine start point.
  20. /// </summary>
  21. public double X1
  22. {
  23. set { SetValue(X1Property, value); }
  24. get { return (double)GetValue(X1Property); }
  25. }
  26. /// <summary>
  27. /// Identifies the Y1 dependency property.
  28. /// </summary>
  29. public static readonly DependencyProperty Y1Property =
  30. DependencyProperty.Register("Y1",
  31. typeof(double), typeof(ArrowLine),
  32. new FrameworkPropertyMetadata(0.0,
  33. FrameworkPropertyMetadataOptions.AffectsMeasure));
  34. /// <summary>
  35. /// Gets or sets the y-coordinate of the ArrowLine start point.
  36. /// </summary>
  37. public double Y1
  38. {
  39. set { SetValue(Y1Property, value); }
  40. get { return (double)GetValue(Y1Property); }
  41. }
  42. /// <summary>
  43. /// Identifies the X2 dependency property.
  44. /// </summary>
  45. public static readonly DependencyProperty X2Property =
  46. DependencyProperty.Register("X2",
  47. typeof(double), typeof(ArrowLine),
  48. new FrameworkPropertyMetadata(0.0,
  49. FrameworkPropertyMetadataOptions.AffectsMeasure));
  50. /// <summary>
  51. /// Gets or sets the x-coordinate of the ArrowLine end point.
  52. /// </summary>
  53. public double X2
  54. {
  55. set { SetValue(X2Property, value); }
  56. get { return (double)GetValue(X2Property); }
  57. }
  58. /// <summary>
  59. /// Identifies the Y2 dependency property.
  60. /// </summary>
  61. public static readonly DependencyProperty Y2Property =
  62. DependencyProperty.Register("Y2",
  63. typeof(double), typeof(ArrowLine),
  64. new FrameworkPropertyMetadata(0.0,
  65. FrameworkPropertyMetadataOptions.AffectsMeasure));
  66. /// <summary>
  67. /// Gets or sets the y-coordinate of the ArrowLine end point.
  68. /// </summary>
  69. public double Y2
  70. {
  71. set { SetValue(Y2Property, value); }
  72. get { return (double)GetValue(Y2Property); }
  73. }
  74. /// <summary>
  75. /// Gets a value that represents the Geometry of the ArrowLine.
  76. /// </summary>
  77. protected override Geometry DefiningGeometry
  78. {
  79. get
  80. {
  81. // Clear out the PathGeometry.
  82. pathgeo.Figures.Clear();
  83. // Define a single PathFigure with the points.
  84. pathfigLine.StartPoint = new Point(X1, Y1);
  85. polysegLine.Points.Clear();
  86. polysegLine.Points.Add(new Point(X2, Y2));
  87. pathgeo.Figures.Add(pathfigLine);
  88. // Call the base property to add arrows on the ends.
  89. return base.DefiningGeometry;
  90. }
  91. }
  92. }
  93. }