TwoColorLineSeries.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. // --------------------------------------------------------------------------------------------------------------------
  2. // <copyright file="TwoColorLineSeries.cs" company="OxyPlot">
  3. // Copyright (c) 2014 OxyPlot contributors
  4. // </copyright>
  5. // <summary>
  6. // The Avalonia wrapper for OxyPlot.TwoColorLineSeries.
  7. // </summary>
  8. // --------------------------------------------------------------------------------------------------------------------
  9. using Avalonia;
  10. namespace OxyPlot.Avalonia
  11. {
  12. using global::Avalonia.Media;
  13. /// <summary>
  14. /// The Avalonia wrapper for OxyPlot.TwoColorLineSeries.
  15. /// </summary>
  16. public class TwoColorLineSeries : LineSeries
  17. {
  18. /// <summary>
  19. /// Identifies the <see cref="Color2"/> dependency property.
  20. /// </summary>
  21. public static readonly StyledProperty<Color> Color2Property = AvaloniaProperty.Register<TwoColorLineSeries, Color>(nameof(Color2), Colors.Blue);
  22. /// <summary>
  23. /// Identifies the <see cref="Limit"/> dependency property.
  24. /// </summary>
  25. public static readonly StyledProperty<double> LimitProperty = AvaloniaProperty.Register<TwoColorLineSeries, double>(nameof(Limit), 0.0);
  26. /// <summary>
  27. /// Identifies the <see cref="LineStyle2"/> dependency property.
  28. /// </summary>
  29. public static readonly StyledProperty<LineStyle> LineStyle2Property = AvaloniaProperty.Register<TwoColorLineSeries, LineStyle>(nameof(LineStyle2), LineStyle.Solid);
  30. /// <summary>
  31. /// Initializes a new instance of the <see cref = "TwoColorLineSeries" /> class.
  32. /// </summary>
  33. public TwoColorLineSeries()
  34. {
  35. InternalSeries = new OxyPlot.Series.TwoColorLineSeries();
  36. }
  37. /// <summary>
  38. /// Gets or sets Color2.
  39. /// </summary>
  40. public Color Color2
  41. {
  42. get
  43. {
  44. return GetValue(Color2Property);
  45. }
  46. set
  47. {
  48. SetValue(Color2Property, value);
  49. }
  50. }
  51. /// <summary>
  52. /// Gets or sets Limit.
  53. /// </summary>
  54. public double Limit
  55. {
  56. get
  57. {
  58. return GetValue(LimitProperty);
  59. }
  60. set
  61. {
  62. SetValue(LimitProperty, value);
  63. }
  64. }
  65. /// <summary>
  66. /// Gets or sets LineStyle2.
  67. /// </summary>
  68. public LineStyle LineStyle2
  69. {
  70. get
  71. {
  72. return GetValue(LineStyle2Property);
  73. }
  74. set
  75. {
  76. SetValue(LineStyle2Property, value);
  77. }
  78. }
  79. /// <summary>
  80. /// Synchronizes the properties.
  81. /// </summary>
  82. /// <param name="series">The series.</param>
  83. protected override void SynchronizeProperties(OxyPlot.Series.Series series)
  84. {
  85. base.SynchronizeProperties(series);
  86. var s = (OxyPlot.Series.TwoColorLineSeries)series;
  87. s.Limit = Limit;
  88. s.Color2 = Color2.ToOxyColor();
  89. }
  90. static TwoColorLineSeries()
  91. {
  92. Color2Property.Changed.AddClassHandler<TwoColorLineSeries>(AppearanceChanged);
  93. LimitProperty.Changed.AddClassHandler<TwoColorLineSeries>(AppearanceChanged);
  94. LineStyle2Property.Changed.AddClassHandler<TwoColorLineSeries>(AppearanceChanged);
  95. }
  96. }
  97. }