// -------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2014 OxyPlot contributors // // // This is a Avalonia wrapper of OxyPlot.TextAnnotation // // -------------------------------------------------------------------------------------------------------------------- using Avalonia; namespace OxyPlot.Avalonia { using global::Avalonia.Layout; using global::Avalonia.Media; /// /// This is a Avalonia wrapper of OxyPlot.TextAnnotation /// public class TextAnnotation : TextualAnnotation { /// /// Identifies the dependency property. /// public static readonly StyledProperty BackgroundProperty = AvaloniaProperty.Register(nameof(Background), MoreColors.Undefined); /// /// Identifies the dependency property. /// public static readonly StyledProperty OffsetProperty = AvaloniaProperty.Register(nameof(Offset), default); /// /// Identifies the dependency property. /// public static readonly StyledProperty PaddingProperty = AvaloniaProperty.Register(nameof(Padding), new Thickness(4)); /// /// Identifies the dependency property. /// public static readonly StyledProperty StrokeProperty = AvaloniaProperty.Register(nameof(Stroke), Colors.Black); /// /// Identifies the dependency property. /// public static readonly StyledProperty StrokeThicknessProperty = AvaloniaProperty.Register(nameof(StrokeThickness), 1.0); /// /// Initializes static members of the class. /// static TextAnnotation() { TextColorProperty.OverrideDefaultValue(MoreColors.Automatic); TextColorProperty.Changed.AddClassHandler(AppearanceChanged); TextHorizontalAlignmentProperty.OverrideDefaultValue(HorizontalAlignment.Right); TextHorizontalAlignmentProperty.Changed.AddClassHandler(AppearanceChanged); TextVerticalAlignmentProperty.OverrideDefaultValue(VerticalAlignment.Top); TextVerticalAlignmentProperty.Changed.AddClassHandler(AppearanceChanged); BackgroundProperty.Changed.AddClassHandler(AppearanceChanged); OffsetProperty.Changed.AddClassHandler(AppearanceChanged); PaddingProperty.Changed.AddClassHandler(AppearanceChanged); StrokeProperty.Changed.AddClassHandler(AppearanceChanged); StrokeThicknessProperty.Changed.AddClassHandler(AppearanceChanged); } /// /// Initializes a new instance of the class. /// public TextAnnotation() { InternalAnnotation = new Annotations.TextAnnotation(); } /// /// Gets or sets the fill color of the background rectangle. /// public Color Background { get { return GetValue(BackgroundProperty); } set { SetValue(BackgroundProperty, value); } } /// /// Gets or sets the position offset (screen coordinates). /// public Vector Offset { get { return GetValue(OffsetProperty); } set { SetValue(OffsetProperty, value); } } /// /// Gets or sets the padding of the background rectangle. /// public Thickness Padding { get { return GetValue(PaddingProperty); } set { SetValue(PaddingProperty, value); } } /// /// Gets or sets the stroke color of the background rectangle. /// public Color Stroke { get { return GetValue(StrokeProperty); } set { SetValue(StrokeProperty, value); } } /// /// Gets or sets the stroke thickness of the background rectangle. /// public double StrokeThickness { get { return GetValue(StrokeThicknessProperty); } set { SetValue(StrokeThicknessProperty, value); } } /// /// Creates the internal annotation object. /// /// The annotation. public override Annotations.Annotation CreateModel() { SynchronizeProperties(); return InternalAnnotation; } /// /// Synchronizes the properties. /// public override void SynchronizeProperties() { base.SynchronizeProperties(); var a = (Annotations.TextAnnotation)InternalAnnotation; a.TextHorizontalAlignment = HorizontalAlignment.ToHorizontalAlignment(); a.Background = Background.ToOxyColor(); a.Offset = Offset.ToScreenVector(); a.TextVerticalAlignment = VerticalAlignment.ToVerticalAlignment(); a.Padding = Padding.ToOxyThickness(); a.Stroke = Stroke.ToOxyColor(); a.StrokeThickness = StrokeThickness; } } }