ShapeAnnotation.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // --------------------------------------------------------------------------------------------------------------------
  2. // <copyright file="ShapeAnnotation.cs" company="OxyPlot">
  3. // Copyright (c) 2014 OxyPlot contributors
  4. // </copyright>
  5. // <summary>
  6. // Provides an abstract base class for shape annotations.
  7. // </summary>
  8. // --------------------------------------------------------------------------------------------------------------------
  9. using Avalonia;
  10. namespace OxyPlot.Avalonia
  11. {
  12. using global::Avalonia.Media;
  13. /// <summary>
  14. /// Provides an abstract base class for shape annotations.
  15. /// </summary>
  16. public abstract class ShapeAnnotation : TextualAnnotation
  17. {
  18. /// <summary>
  19. /// Identifies the <see cref="Fill"/> dependency property.
  20. /// </summary>
  21. public static readonly StyledProperty<Color> FillProperty = AvaloniaProperty.Register<ShapeAnnotation, Color>(nameof(Fill), Colors.LightBlue);
  22. /// <summary>
  23. /// Identifies the <see cref="Stroke"/> dependency property.
  24. /// </summary>
  25. public static readonly StyledProperty<Color> StrokeProperty = AvaloniaProperty.Register<ShapeAnnotation, Color>(nameof(Stroke), Colors.Black);
  26. /// <summary>
  27. /// Identifies the <see cref="StrokeThickness"/> dependency property.
  28. /// </summary>
  29. public static readonly StyledProperty<double> StrokeThicknessProperty = AvaloniaProperty.Register<ShapeAnnotation, double>(nameof(StrokeThickness), 0.0);
  30. /// <summary>
  31. /// Gets or sets the fill color.
  32. /// </summary>
  33. public Color Fill
  34. {
  35. get
  36. {
  37. return GetValue(FillProperty);
  38. }
  39. set
  40. {
  41. SetValue(FillProperty, value);
  42. }
  43. }
  44. /// <summary>
  45. /// Gets or sets the stroke color.
  46. /// </summary>
  47. public Color Stroke
  48. {
  49. get
  50. {
  51. return GetValue(StrokeProperty);
  52. }
  53. set
  54. {
  55. SetValue(StrokeProperty, value);
  56. }
  57. }
  58. /// <summary>
  59. /// Gets or sets the stroke thickness.
  60. /// </summary>
  61. public double StrokeThickness
  62. {
  63. get
  64. {
  65. return GetValue(StrokeThicknessProperty);
  66. }
  67. set
  68. {
  69. SetValue(StrokeThicknessProperty, value);
  70. }
  71. }
  72. /// <summary>
  73. /// Synchronizes the properties.
  74. /// </summary>
  75. public override void SynchronizeProperties()
  76. {
  77. base.SynchronizeProperties();
  78. var a = (Annotations.ShapeAnnotation)InternalAnnotation;
  79. a.Fill = Fill.ToOxyColor();
  80. a.Stroke = Stroke.ToOxyColor();
  81. a.StrokeThickness = StrokeThickness;
  82. }
  83. static ShapeAnnotation()
  84. {
  85. FillProperty.Changed.AddClassHandler<ShapeAnnotation>(AppearanceChanged);
  86. StrokeProperty.Changed.AddClassHandler<ShapeAnnotation>(AppearanceChanged);
  87. StrokeThicknessProperty.Changed.AddClassHandler<ShapeAnnotation>(AppearanceChanged);
  88. }
  89. }
  90. }