diff --git a/MapControl/Avalonia/MapGraticule.Avalonia.cs b/MapControl/Avalonia/MapGraticule.Avalonia.cs index ea7c8dfd..adbcf8f1 100644 --- a/MapControl/Avalonia/MapGraticule.Avalonia.cs +++ b/MapControl/Avalonia/MapGraticule.Avalonia.cs @@ -1,47 +1,15 @@ -using Avalonia.Controls.Shapes; +using Avalonia.Controls.Primitives; using System.Collections.Generic; using System.Globalization; using System.Linq; namespace MapControl { - public partial class MapGraticule : Control, IMapElement + public partial class MapGraticule : TemplatedControl, IMapElement { - public static readonly StyledProperty ForegroundProperty = - DependencyPropertyHelper.AddOwner(TextElement.ForegroundProperty, null, - (graticule, oldValue, newValue) => graticule.InvalidateVisual()); - - public static readonly StyledProperty FontFamilyProperty = - DependencyPropertyHelper.AddOwner(TextElement.FontFamilyProperty); - - public static readonly StyledProperty FontSizeProperty = - DependencyPropertyHelper.AddOwner(TextElement.FontSizeProperty); - - public static readonly StyledProperty StrokeThicknessProperty = - DependencyPropertyHelper.AddOwner(Shape.StrokeThicknessProperty, 0.5); - - public Brush Foreground + static MapGraticule() { - get => GetValue(ForegroundProperty); - set => SetValue(ForegroundProperty, value); - } - - public FontFamily FontFamily - { - get => GetValue(FontFamilyProperty); - set => SetValue(FontFamilyProperty, value); - } - - public double FontSize - { - get => GetValue(FontSizeProperty); - set => SetValue(FontSizeProperty, value); - } - - public double StrokeThickness - { - get => GetValue(StrokeThicknessProperty); - set => SetValue(StrokeThicknessProperty, value); + ForegroundProperty.Changed.AddClassHandler((graticule, e) => graticule.InvalidateVisual()); } private MapBase parentMap; @@ -91,7 +59,7 @@ namespace MapControl if (labels.Count > 0) { - var typeface = new Typeface(FontFamily, FontStyle.Normal, FontWeight.Normal, FontStretch.Normal); + var typeface = new Typeface(FontFamily, FontStyle, FontWeight, FontStretch); foreach (var label in labels) { diff --git a/MapControl/Shared/MapGraticule.cs b/MapControl/Shared/MapGraticule.cs index 89ff2b35..6478e767 100644 --- a/MapControl/Shared/MapGraticule.cs +++ b/MapControl/Shared/MapGraticule.cs @@ -40,11 +40,17 @@ namespace MapControl private const double LineInterpolationResolution = 2d; + public static readonly DependencyProperty StrokeThicknessProperty = + DependencyPropertyHelper.Register(nameof(StrokeThickness), 0.5); + public static readonly DependencyProperty MinLineDistanceProperty = DependencyPropertyHelper.Register(nameof(MinLineDistance), 150d); - private double lineDistance; - private string labelFormat; + public double StrokeThickness + { + get => (double)GetValue(StrokeThicknessProperty); + set => SetValue(StrokeThicknessProperty, value); + } /// /// Minimum graticule line distance in pixels. The default value is 150. @@ -55,6 +61,9 @@ namespace MapControl set => SetValue(MinLineDistanceProperty, value); } + private double lineDistance; + private string labelFormat; + private void SetLineDistance() { var minDistance = MinLineDistance / PixelPerLongitudeDegree(ParentMap.Center); diff --git a/MapControl/WPF/MapGraticule.WPF.cs b/MapControl/WPF/MapGraticule.WPF.cs index 18e15651..4442ee44 100644 --- a/MapControl/WPF/MapGraticule.WPF.cs +++ b/MapControl/WPF/MapGraticule.WPF.cs @@ -9,15 +9,6 @@ namespace MapControl { public partial class MapGraticule : Control, IMapElement { - public static readonly DependencyProperty StrokeThicknessProperty = - DependencyPropertyHelper.Register(nameof(StrokeThickness), 0.5); - - public double StrokeThickness - { - get => (double)GetValue(StrokeThicknessProperty); - set => SetValue(StrokeThicknessProperty, value); - } - private MapBase parentMap; /// diff --git a/MapControl/WinUI/MapGraticule.WinUI.cs b/MapControl/WinUI/MapGraticule.WinUI.cs index 99df887d..539a2697 100644 --- a/MapControl/WinUI/MapGraticule.WinUI.cs +++ b/MapControl/WinUI/MapGraticule.WinUI.cs @@ -28,9 +28,6 @@ namespace MapControl public static readonly DependencyProperty FontSizeProperty = DependencyPropertyHelper.Register(nameof(FontSize), 12d); - public static readonly DependencyProperty StrokeThicknessProperty = - DependencyPropertyHelper.Register(nameof(StrokeThickness), 0.5); - private readonly Path path = new Path { Data = new PathGeometry() }; public Brush Foreground @@ -51,12 +48,6 @@ namespace MapControl set => SetValue(FontSizeProperty, value); } - public double StrokeThickness - { - get => (double)GetValue(StrokeThicknessProperty); - set => SetValue(StrokeThicknessProperty, value); - } - protected override void SetParentMap(MapBase map) { if (map != null && Foreground == null)