RectangleAnnotation.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. // --------------------------------------------------------------------------------------------------------------------
  2. // <copyright file="RectangleAnnotation.cs" company="OxyPlot">
  3. // Copyright (c) 2014 OxyPlot contributors
  4. // </copyright>
  5. // <summary>
  6. // This is a Avalonia wrapper of OxyPlot.RectangleAnnotation
  7. // </summary>
  8. // --------------------------------------------------------------------------------------------------------------------
  9. using Avalonia;
  10. namespace OxyPlot.Avalonia
  11. {
  12. /// <summary>
  13. /// This is a Avalonia wrapper of OxyPlot.RectangleAnnotation
  14. /// </summary>
  15. public class RectangleAnnotation : ShapeAnnotation
  16. {
  17. /// <summary>
  18. /// Identifies the <see cref="MaximumX"/> dependency property.
  19. /// </summary>
  20. public static readonly StyledProperty<double> MaximumXProperty = AvaloniaProperty.Register<RectangleAnnotation, double>(nameof(MaximumX), double.MaxValue);
  21. /// <summary>
  22. /// Identifies the <see cref="MaximumY"/> dependency property.
  23. /// </summary>
  24. public static readonly StyledProperty<double> MaximumYProperty = AvaloniaProperty.Register<RectangleAnnotation, double>(nameof(MaximumY), double.MaxValue);
  25. /// <summary>
  26. /// Identifies the <see cref="MinimumX"/> dependency property.
  27. /// </summary>
  28. public static readonly StyledProperty<double> MinimumXProperty = AvaloniaProperty.Register<RectangleAnnotation, double>(nameof(MinimumX), double.MinValue);
  29. /// <summary>
  30. /// Identifies the <see cref="MinimumY"/> dependency property.
  31. /// </summary>
  32. public static readonly StyledProperty<double> MinimumYProperty = AvaloniaProperty.Register<RectangleAnnotation, double>(nameof(MinimumY), double.MinValue);
  33. /// <summary>
  34. /// Initializes static members of the <see cref="RectangleAnnotation"/> class.
  35. /// </summary>
  36. static RectangleAnnotation()
  37. {
  38. TextColorProperty.OverrideDefaultValue<RectangleAnnotation>(MoreColors.Automatic);
  39. TextColorProperty.Changed.AddClassHandler<RectangleAnnotation>(AppearanceChanged);
  40. MaximumXProperty.Changed.AddClassHandler<RectangleAnnotation>(DataChanged);
  41. MaximumYProperty.Changed.AddClassHandler<RectangleAnnotation>(DataChanged);
  42. MinimumXProperty.Changed.AddClassHandler<RectangleAnnotation>(DataChanged);
  43. MinimumYProperty.Changed.AddClassHandler<RectangleAnnotation>(DataChanged);
  44. }
  45. /// <summary>
  46. /// Initializes a new instance of the <see cref="RectangleAnnotation" /> class.
  47. /// </summary>
  48. public RectangleAnnotation()
  49. {
  50. InternalAnnotation = new Annotations.RectangleAnnotation();
  51. }
  52. /// <summary>
  53. /// Gets or sets the Maximum X.
  54. /// </summary>
  55. public double MaximumX
  56. {
  57. get
  58. {
  59. return GetValue(MaximumXProperty);
  60. }
  61. set
  62. {
  63. SetValue(MaximumXProperty, value);
  64. }
  65. }
  66. /// <summary>
  67. /// Gets or sets the Maximum Y.
  68. /// </summary>
  69. public double MaximumY
  70. {
  71. get
  72. {
  73. return GetValue(MaximumYProperty);
  74. }
  75. set
  76. {
  77. SetValue(MaximumYProperty, value);
  78. }
  79. }
  80. /// <summary>
  81. /// Gets or sets the Minimum X.
  82. /// </summary>
  83. public double MinimumX
  84. {
  85. get
  86. {
  87. return GetValue(MinimumXProperty);
  88. }
  89. set
  90. {
  91. SetValue(MinimumXProperty, value);
  92. }
  93. }
  94. /// <summary>
  95. /// Gets or sets the Minimum Y.
  96. /// </summary>
  97. public double MinimumY
  98. {
  99. get
  100. {
  101. return GetValue(MinimumYProperty);
  102. }
  103. set
  104. {
  105. SetValue(MinimumYProperty, value);
  106. }
  107. }
  108. /// <summary>
  109. /// Creates the internal annotation object.
  110. /// </summary>
  111. /// <returns>The annotation.</returns>
  112. public override Annotations.Annotation CreateModel()
  113. {
  114. SynchronizeProperties();
  115. return InternalAnnotation;
  116. }
  117. /// <summary>
  118. /// Synchronizes the properties.
  119. /// </summary>
  120. public override void SynchronizeProperties()
  121. {
  122. base.SynchronizeProperties();
  123. var a = (Annotations.RectangleAnnotation)InternalAnnotation;
  124. a.MinimumX = MinimumX;
  125. a.MaximumX = MaximumX;
  126. a.MinimumY = MinimumY;
  127. a.MaximumY = MaximumY;
  128. }
  129. }
  130. }