DependencyPropertyHelper

This commit is contained in:
ClemensFischer 2024-05-23 18:08:14 +02:00
parent c74c2b1fed
commit 8e82e0bcbd
25 changed files with 224 additions and 176 deletions

View file

@ -18,9 +18,9 @@ namespace MapControl.MBTiles
/// </summary> /// </summary>
public class MBTileLayer : MapTileLayer public class MBTileLayer : MapTileLayer
{ {
public static readonly DependencyProperty FileProperty = DependencyProperty.Register( public static readonly DependencyProperty FileProperty =
nameof(File), typeof(string), typeof(MBTileLayer), DependencyPropertyHelper.Register<MBTileLayer, string>(nameof(File), null, false,
new PropertyMetadata(null, async (o, e) => await ((MBTileLayer)o).FilePropertyChanged((string)e.NewValue))); async (layer, oldValue, newValue) => await layer.FilePropertyChanged(newValue));
public string File public string File
{ {

View file

@ -51,9 +51,9 @@ namespace MapControl
private static string QueryString(ushort tag) => $"/ifd/{{ushort={tag}}}"; private static string QueryString(ushort tag) => $"/ifd/{{ushort={tag}}}";
public static readonly DependencyProperty SourcePathProperty = DependencyProperty.Register( public static readonly DependencyProperty SourcePathProperty =
nameof(SourcePath), typeof(string), typeof(GeoImage), DependencyPropertyHelper.Register<GeoImage, string>(nameof(SourcePath), null, false,
new PropertyMetadata(null, async (o, e) => await ((GeoImage)o).SourcePathPropertyChanged((string)e.NewValue))); async (image, oldValue, newValue) => await image.SourcePathPropertyChanged(newValue));
public GeoImage() public GeoImage()
{ {

View file

@ -44,8 +44,8 @@ namespace MapControl
private const double LineInterpolationResolution = 2d; private const double LineInterpolationResolution = 2d;
public static readonly DependencyProperty MinLineDistanceProperty = DependencyProperty.Register( public static readonly DependencyProperty MinLineDistanceProperty =
nameof(MinLineDistance), typeof(double), typeof(MapGraticule), new PropertyMetadata(150d)); DependencyPropertyHelper.Register<MapGraticule, double>(nameof(MinLineDistance), 150d);
private double lineDistance; private double lineDistance;
private string labelFormat; private string labelFormat;

View file

@ -24,8 +24,8 @@ namespace MapControl
/// </summary> /// </summary>
public partial class MapItemsControl : ListBox public partial class MapItemsControl : ListBox
{ {
public static readonly DependencyProperty LocationMemberPathProperty = DependencyProperty.Register( public static readonly DependencyProperty LocationMemberPathProperty =
nameof(LocationMemberPath), typeof(string), typeof(MapItemsControl), new PropertyMetadata(null)); DependencyPropertyHelper.Register<MapItemsControl, string>(nameof(LocationMemberPath));
/// <summary> /// <summary>
/// Path to a source property for binding the Location property of MapItem containers. /// Path to a source property for binding the Location property of MapItem containers.

View file

@ -23,9 +23,9 @@ namespace MapControl
/// </summary> /// </summary>
public partial class MapPath : IMapElement public partial class MapPath : IMapElement
{ {
public static readonly DependencyProperty LocationProperty = DependencyProperty.Register( public static readonly DependencyProperty LocationProperty =
nameof(Location), typeof(Location), typeof(MapPath), DependencyPropertyHelper.Register<MapPath, Location>(nameof(Location), null, false,
new PropertyMetadata(null, (o, e) => ((MapPath)o).UpdateData())); (path, oldValue, newValue) => path.UpdateData());
private MapBase parentMap; private MapBase parentMap;

View file

@ -21,13 +21,13 @@ namespace MapControl
/// </summary> /// </summary>
public class MapPolygon : MapPath public class MapPolygon : MapPath
{ {
public static readonly DependencyProperty LocationsProperty = DependencyProperty.Register( public static readonly DependencyProperty LocationsProperty =
nameof(Locations), typeof(IEnumerable<Location>), typeof(MapPolygon), DependencyPropertyHelper.Register<MapPolygon, IEnumerable<Location>>(nameof(Locations), null, false,
new PropertyMetadata(null, (o, e) => ((MapPolygon)o).DataCollectionPropertyChanged(e))); (polygon, oldValue, newValue) => polygon.DataCollectionPropertyChanged(oldValue, newValue));
public static readonly DependencyProperty FillRuleProperty = DependencyProperty.Register( public static readonly DependencyProperty FillRuleProperty =
nameof(FillRule), typeof(FillRule), typeof(MapPolygon), DependencyPropertyHelper.Register<MapPolygon, FillRule>(nameof(FillRule), FillRule.EvenOdd, false,
new PropertyMetadata(FillRule.EvenOdd, (o, e) => ((PathGeometry)((MapPolygon)o).Data).FillRule = (FillRule)e.NewValue)); (polygon, oldValue, newValue) => ((PathGeometry)polygon.Data).FillRule = newValue);
/// <summary> /// <summary>
/// Gets or sets the Locations that define the polygon points. /// Gets or sets the Locations that define the polygon points.

View file

@ -21,13 +21,13 @@ namespace MapControl
/// </summary> /// </summary>
public class MapPolyline : MapPath public class MapPolyline : MapPath
{ {
public static readonly DependencyProperty LocationsProperty = DependencyProperty.Register( public static readonly DependencyProperty LocationsProperty =
nameof(Locations), typeof(IEnumerable<Location>), typeof(MapPolyline), DependencyPropertyHelper.Register<MapPolyline, IEnumerable<Location>>(nameof(Locations), null, false,
new PropertyMetadata(null, (o, e) => ((MapPolyline)o).DataCollectionPropertyChanged(e))); (polyline, oldValue, newValue) => polyline.DataCollectionPropertyChanged(oldValue, newValue));
public static readonly DependencyProperty FillRuleProperty = DependencyProperty.Register( public static readonly DependencyProperty FillRuleProperty =
nameof(FillRule), typeof(FillRule), typeof(MapPolyline), DependencyPropertyHelper.Register<MapPolyline, FillRule>(nameof(FillRule), FillRule.EvenOdd, false,
new PropertyMetadata(FillRule.EvenOdd, (o, e) => ((PathGeometry)((MapPolyline)o).Data).FillRule = (FillRule)e.NewValue)); (polyline, oldValue, newValue) => ((PathGeometry)polyline.Data).FillRule = newValue);
/// <summary> /// <summary>
/// Gets or sets the Locations that define the polyline points. /// Gets or sets the Locations that define the polyline points.

View file

@ -30,8 +30,8 @@ namespace MapControl
/// </summary> /// </summary>
public class MapScale : MapOverlay public class MapScale : MapOverlay
{ {
public static readonly DependencyProperty PaddingProperty = DependencyProperty.Register( public static readonly DependencyProperty PaddingProperty =
nameof(Padding), typeof(Thickness), typeof(MapScale), new PropertyMetadata(new Thickness(4))); DependencyPropertyHelper.Register<MapScale, Thickness>(nameof(Padding), new Thickness(4));
private readonly Polyline line = new Polyline(); private readonly Polyline line = new Polyline();

View file

@ -9,6 +9,15 @@ namespace MapControl
{ {
public static class DependencyPropertyHelper public static class DependencyPropertyHelper
{ {
public static DependencyProperty Register<TOwner, TValue>(
string name,
TValue defaultValue,
FrameworkPropertyMetadataOptions options)
where TOwner : DependencyObject
{
return DependencyProperty.Register(name, typeof(TValue), typeof(TOwner), new FrameworkPropertyMetadata(defaultValue, options));
}
public static DependencyProperty Register<TOwner, TValue>( public static DependencyProperty Register<TOwner, TValue>(
string name, string name,
TValue defaultValue = default, TValue defaultValue = default,
@ -64,5 +73,35 @@ namespace MapControl
{ {
return DependencyProperty.RegisterReadOnly(name, typeof(TValue), typeof(TOwner), new PropertyMetadata(defaultValue)); return DependencyProperty.RegisterReadOnly(name, typeof(TValue), typeof(TOwner), new PropertyMetadata(defaultValue));
} }
public static DependencyProperty AddOwner<TOwner>(
DependencyProperty property,
FrameworkPropertyMetadataOptions options = FrameworkPropertyMetadataOptions.None)
where TOwner : DependencyObject
{
FrameworkPropertyMetadata metadata = null;
if (options != FrameworkPropertyMetadataOptions.None)
{
metadata = new FrameworkPropertyMetadata(property.DefaultMetadata.DefaultValue, options);
}
return property.AddOwner(typeof(TOwner), metadata);
}
public static DependencyProperty AddOwner<TOwner, TValue>(
DependencyProperty property,
Action<TOwner, TValue, TValue> changed)
where TOwner : DependencyObject
{
FrameworkPropertyMetadata metadata = null;
if (changed != null)
{
metadata = new FrameworkPropertyMetadata((o, e) => changed((TOwner)o, (TValue)e.OldValue, (TValue)e.NewValue));
}
return property.AddOwner(typeof(TOwner), metadata);
}
} }
} }

View file

@ -13,12 +13,11 @@ namespace MapControl
/// </summary> /// </summary>
public class Map : MapBase public class Map : MapBase
{ {
public static readonly DependencyProperty MouseWheelZoomDeltaProperty = DependencyProperty.Register( public static readonly DependencyProperty MouseWheelZoomDeltaProperty =
nameof(MouseWheelZoomDelta), typeof(double), typeof(Map), new PropertyMetadata(0.25)); DependencyPropertyHelper.Register<Map, double>(nameof(MouseWheelZoomDelta), 0.25);
public static readonly DependencyProperty ManipulationModeProperty = DependencyProperty.Register( public static readonly DependencyProperty ManipulationModeProperty =
nameof(ManipulationMode), typeof(ManipulationModes), typeof(Map), DependencyPropertyHelper.Register<Map, ManipulationModes>(nameof(ManipulationMode), ManipulationModes.Scale | ManipulationModes.Translate);
new PropertyMetadata(ManipulationModes.Scale | ManipulationModes.Translate));
private Point? mousePosition; private Point? mousePosition;
private double mouseWheelDelta; private double mouseWheelDelta;

View file

@ -12,9 +12,11 @@ namespace MapControl
/// </summary> /// </summary>
public class MapContentControl : ContentControl public class MapContentControl : ContentControl
{ {
public static readonly DependencyProperty AutoCollapseProperty = MapPanel.AutoCollapseProperty.AddOwner(typeof(MapContentControl)); public static readonly DependencyProperty AutoCollapseProperty =
DependencyPropertyHelper.AddOwner<MapContentControl>(MapPanel.AutoCollapseProperty);
public static readonly DependencyProperty LocationProperty = MapPanel.LocationProperty.AddOwner(typeof(MapContentControl)); public static readonly DependencyProperty LocationProperty =
DependencyPropertyHelper.AddOwner<MapContentControl>(MapPanel.LocationProperty);
static MapContentControl() static MapContentControl()
{ {
@ -50,8 +52,8 @@ namespace MapControl
DefaultStyleKeyProperty.OverrideMetadata(typeof(Pushpin), new FrameworkPropertyMetadata(typeof(Pushpin))); DefaultStyleKeyProperty.OverrideMetadata(typeof(Pushpin), new FrameworkPropertyMetadata(typeof(Pushpin)));
} }
public static readonly DependencyProperty CornerRadiusProperty = DependencyProperty.Register( public static readonly DependencyProperty CornerRadiusProperty =
nameof(CornerRadius), typeof(CornerRadius), typeof(Pushpin)); DependencyPropertyHelper.Register<Pushpin, CornerRadius>(nameof(CornerRadius));
public CornerRadius CornerRadius public CornerRadius CornerRadius
{ {

View file

@ -10,12 +10,12 @@ namespace MapControl
{ {
public partial class MapItem public partial class MapItem
{ {
public static readonly DependencyProperty AutoCollapseProperty = MapPanel.AutoCollapseProperty.AddOwner( public static readonly DependencyProperty AutoCollapseProperty =
typeof(MapItem)); DependencyPropertyHelper.AddOwner<MapItem>(MapPanel.AutoCollapseProperty);
public static readonly DependencyProperty LocationProperty = MapPanel.LocationProperty.AddOwner( public static readonly DependencyProperty LocationProperty =
typeof(MapItem), new FrameworkPropertyMetadata(null, DependencyPropertyHelper.AddOwner<MapItem, Location>(MapPanel.LocationProperty,
(o, e) => ((MapItem)o).UpdateMapTransform((Location)e.NewValue))); (item, oldValue, newValue) => item.UpdateMapTransform(newValue));
static MapItem() static MapItem()
{ {

View file

@ -20,8 +20,8 @@ namespace MapControl
public class MapItemsImageLayer : MapImageLayer public class MapItemsImageLayer : MapImageLayer
{ {
public static readonly DependencyProperty ItemsSourceProperty = DependencyProperty.Register( public static readonly DependencyProperty ItemsSourceProperty =
nameof(ItemsSource), typeof(IEnumerable<IMapDrawingItem>), typeof(MapItemsImageLayer)); DependencyPropertyHelper.Register<MapItemsImageLayer, IEnumerable<IMapDrawingItem>>(nameof(ItemsSource));
public IEnumerable<IMapDrawingItem> ItemsSource public IEnumerable<IMapDrawingItem> ItemsSource
{ {

View file

@ -18,13 +18,13 @@ namespace MapControl
/// </summary> /// </summary>
public class MapMultiPolygon : MapPath public class MapMultiPolygon : MapPath
{ {
public static readonly DependencyProperty PolygonsProperty = DependencyProperty.Register( public static readonly DependencyProperty PolygonsProperty =
nameof(Polygons), typeof(IEnumerable<IEnumerable<Location>>), typeof(MapMultiPolygon), DependencyPropertyHelper.Register<MapMultiPolygon, IEnumerable<IEnumerable<Location>>>(nameof(Polygons), null, false,
new PropertyMetadata(null, (o, e) => ((MapMultiPolygon)o).DataCollectionPropertyChanged(e))); (polygon, oldValue, newValue) => polygon.DataCollectionPropertyChanged(oldValue, newValue));
public static readonly DependencyProperty FillRuleProperty = DependencyProperty.Register( public static readonly DependencyProperty FillRuleProperty =
nameof(FillRule), typeof(FillRule), typeof(MapMultiPolygon), DependencyPropertyHelper.Register<MapMultiPolygon, FillRule>(nameof(FillRule), FillRule.EvenOdd, false,
new PropertyMetadata(FillRule.EvenOdd, (o, e) => ((PathGeometry)((MapMultiPolygon)o).Data).FillRule = (FillRule)e.NewValue)); (polygon, oldValue, newValue) => ((PathGeometry)polygon.Data).FillRule = newValue);
/// <summary> /// <summary>
/// Gets or sets the Locations that define the multi-polygon points. /// Gets or sets the Locations that define the multi-polygon points.

View file

@ -12,50 +12,65 @@ namespace MapControl
{ {
public partial class MapOverlay public partial class MapOverlay
{ {
public static readonly DependencyProperty FontFamilyProperty = TextElement.FontFamilyProperty.AddOwner( public static readonly DependencyProperty FontFamilyProperty =
typeof(MapOverlay), new FrameworkPropertyMetadata { AffectsRender = true, Inherits = true }); DependencyPropertyHelper.AddOwner<MapOverlay>(TextElement.FontFamilyProperty,
FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.Inherits);
public static readonly DependencyProperty FontSizeProperty = TextElement.FontSizeProperty.AddOwner( public static readonly DependencyProperty FontSizeProperty =
typeof(MapOverlay), new FrameworkPropertyMetadata { AffectsRender = true, Inherits = true }); DependencyPropertyHelper.AddOwner<MapOverlay>(TextElement.FontSizeProperty,
FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.Inherits);
public static readonly DependencyProperty FontStyleProperty = TextElement.FontStyleProperty.AddOwner( public static readonly DependencyProperty FontStyleProperty =
typeof(MapOverlay), new FrameworkPropertyMetadata { AffectsRender = true, Inherits = true }); DependencyPropertyHelper.AddOwner<MapOverlay>(TextElement.FontStyleProperty,
FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.Inherits);
public static readonly DependencyProperty FontStretchProperty = TextElement.FontStretchProperty.AddOwner( public static readonly DependencyProperty FontStretchProperty =
typeof(MapOverlay), new FrameworkPropertyMetadata { AffectsRender = true, Inherits = true }); DependencyPropertyHelper.AddOwner<MapOverlay>(TextElement.FontStretchProperty,
FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.Inherits);
public static readonly DependencyProperty FontWeightProperty = TextElement.FontWeightProperty.AddOwner( public static readonly DependencyProperty FontWeightProperty =
typeof(MapOverlay), new FrameworkPropertyMetadata { AffectsRender = true, Inherits = true }); DependencyPropertyHelper.AddOwner<MapOverlay>(TextElement.FontWeightProperty,
FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.Inherits);
public static readonly DependencyProperty ForegroundProperty = TextElement.ForegroundProperty.AddOwner( public static readonly DependencyProperty ForegroundProperty =
typeof(MapOverlay), new FrameworkPropertyMetadata { AffectsRender = true, Inherits = true }); DependencyPropertyHelper.AddOwner<MapOverlay>(TextElement.ForegroundProperty,
FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.Inherits);
public static readonly DependencyProperty StrokeProperty = Shape.StrokeProperty.AddOwner( public static readonly DependencyProperty StrokeProperty =
typeof(MapOverlay), new FrameworkPropertyMetadata { AffectsRender = true }); DependencyPropertyHelper.AddOwner<MapOverlay>(Shape.StrokeProperty,
FrameworkPropertyMetadataOptions.AffectsRender);
public static readonly DependencyProperty StrokeThicknessProperty = Shape.StrokeThicknessProperty.AddOwner( public static readonly DependencyProperty StrokeThicknessProperty =
typeof(MapOverlay), new FrameworkPropertyMetadata { AffectsRender = true }); DependencyPropertyHelper.AddOwner<MapOverlay>(Shape.StrokeThicknessProperty,
FrameworkPropertyMetadataOptions.AffectsRender);
public static readonly DependencyProperty StrokeDashArrayProperty = Shape.StrokeDashArrayProperty.AddOwner( public static readonly DependencyProperty StrokeDashArrayProperty =
typeof(MapOverlay), new FrameworkPropertyMetadata { AffectsRender = true }); DependencyPropertyHelper.AddOwner<MapOverlay>(Shape.StrokeDashArrayProperty,
FrameworkPropertyMetadataOptions.AffectsRender);
public static readonly DependencyProperty StrokeDashOffsetProperty = Shape.StrokeDashOffsetProperty.AddOwner( public static readonly DependencyProperty StrokeDashOffsetProperty =
typeof(MapOverlay), new FrameworkPropertyMetadata { AffectsRender = true }); DependencyPropertyHelper.AddOwner<MapOverlay>(Shape.StrokeDashOffsetProperty,
FrameworkPropertyMetadataOptions.AffectsRender);
public static readonly DependencyProperty StrokeDashCapProperty = Shape.StrokeDashCapProperty.AddOwner( public static readonly DependencyProperty StrokeDashCapProperty =
typeof(MapOverlay), new FrameworkPropertyMetadata { AffectsRender = true }); DependencyPropertyHelper.AddOwner<MapOverlay>(Shape.StrokeDashCapProperty,
FrameworkPropertyMetadataOptions.AffectsRender);
public static readonly DependencyProperty StrokeStartLineCapProperty = Shape.StrokeStartLineCapProperty.AddOwner( public static readonly DependencyProperty StrokeStartLineCapProperty =
typeof(MapOverlay), new FrameworkPropertyMetadata { AffectsRender = true }); DependencyPropertyHelper.AddOwner<MapOverlay>(Shape.StrokeStartLineCapProperty,
FrameworkPropertyMetadataOptions.AffectsRender);
public static readonly DependencyProperty StrokeEndLineCapProperty = Shape.StrokeEndLineCapProperty.AddOwner( public static readonly DependencyProperty StrokeEndLineCapProperty =
typeof(MapOverlay), new FrameworkPropertyMetadata { AffectsRender = true }); DependencyPropertyHelper.AddOwner<MapOverlay>(Shape.StrokeEndLineCapProperty,
FrameworkPropertyMetadataOptions.AffectsRender);
public static readonly DependencyProperty StrokeLineJoinProperty = Shape.StrokeLineJoinProperty.AddOwner( public static readonly DependencyProperty StrokeLineJoinProperty =
typeof(MapOverlay), new FrameworkPropertyMetadata { AffectsRender = true }); DependencyPropertyHelper.AddOwner<MapOverlay>(Shape.StrokeLineJoinProperty,
FrameworkPropertyMetadataOptions.AffectsRender);
public static readonly DependencyProperty StrokeMiterLimitProperty = Shape.StrokeMiterLimitProperty.AddOwner( public static readonly DependencyProperty StrokeMiterLimitProperty =
typeof(MapOverlay), new FrameworkPropertyMetadata { AffectsRender = true }); DependencyPropertyHelper.AddOwner<MapOverlay>(Shape.StrokeMiterLimitProperty,
FrameworkPropertyMetadataOptions.AffectsRender);
protected override void OnInitialized(EventArgs e) protected override void OnInitialized(EventArgs e)
{ {

View file

@ -3,6 +3,7 @@
// Licensed under the Microsoft Public License (Ms-PL) // Licensed under the Microsoft Public License (Ms-PL)
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Specialized; using System.Collections.Specialized;
using System.Linq; using System.Linq;
@ -19,8 +20,9 @@ namespace MapControl
Stretch = Stretch.None; Stretch = Stretch.None;
} }
public static readonly DependencyProperty DataProperty = Path.DataProperty.AddOwner( public static readonly DependencyProperty DataProperty =
typeof(MapPath), new PropertyMetadata(null, DataPropertyChanged)); DependencyPropertyHelper.AddOwner<MapPath, Geometry>(Path.DataProperty,
(path, oldValue, newValue) => path.DataPropertyChanged(oldValue, newValue));
public Geometry Data public Geometry Data
{ {
@ -30,23 +32,19 @@ namespace MapControl
protected override Geometry DefiningGeometry => Data; protected override Geometry DefiningGeometry => Data;
private static void DataPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) private void DataPropertyChanged(Geometry oldData, Geometry newData)
{ {
var data = (Geometry)e.NewValue;
// Check if data is actually a new Geometry. // Check if data is actually a new Geometry.
// //
if (data != null && !ReferenceEquals(data, e.OldValue)) if (newData != null && !ReferenceEquals(newData, oldData))
{ {
var path = (MapPath)obj; if (newData.IsFrozen)
if (data.IsFrozen)
{ {
path.Data = data.Clone(); // DataPropertyChanged called again Data = newData.Clone(); // DataPropertyChanged called again
} }
else else
{ {
path.UpdateData(); UpdateData();
} }
} }
} }
@ -65,14 +63,14 @@ namespace MapControl
#region Methods used only by derived classes MapPolyline, MapPolygon and MapMultiPolygon #region Methods used only by derived classes MapPolyline, MapPolygon and MapMultiPolygon
protected void DataCollectionPropertyChanged(DependencyPropertyChangedEventArgs e) protected void DataCollectionPropertyChanged(IEnumerable oldValue, IEnumerable newValue)
{ {
if (e.OldValue is INotifyCollectionChanged oldCollection) if (oldValue is INotifyCollectionChanged oldCollection)
{ {
CollectionChangedEventManager.RemoveListener(oldCollection, this); CollectionChangedEventManager.RemoveListener(oldCollection, this);
} }
if (e.NewValue is INotifyCollectionChanged newCollection) if (newValue is INotifyCollectionChanged newCollection)
{ {
CollectionChangedEventManager.AddListener(newCollection, this); CollectionChangedEventManager.AddListener(newCollection, this);
} }

View file

@ -11,35 +11,29 @@ namespace MapControl
{ {
public partial class PushpinBorder : Decorator public partial class PushpinBorder : Decorator
{ {
public static readonly DependencyProperty ArrowSizeProperty = DependencyProperty.Register( public static readonly DependencyProperty ArrowSizeProperty =
nameof(ArrowSize), typeof(Size), typeof(PushpinBorder), DependencyPropertyHelper.Register<PushpinBorder, Size>(nameof(ArrowSize), new Size(10d, 20d),
new FrameworkPropertyMetadata(new Size(10d, 20d), FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender);
FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender));
public static readonly DependencyProperty BorderWidthProperty = DependencyProperty.Register( public static readonly DependencyProperty BorderWidthProperty =
nameof(BorderWidth), typeof(double), typeof(PushpinBorder), DependencyPropertyHelper.Register<PushpinBorder, double>(nameof(BorderWidth), 0d,
new FrameworkPropertyMetadata(0d, FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender);
FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender));
public static readonly DependencyProperty BackgroundProperty = DependencyProperty.Register( public static readonly DependencyProperty BackgroundProperty =
nameof(Background), typeof(Brush), typeof(PushpinBorder), DependencyPropertyHelper.Register<PushpinBorder, Brush>(nameof(Background), null,
new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender);
FrameworkPropertyMetadataOptions.AffectsRender));
public static readonly DependencyProperty BorderBrushProperty = DependencyProperty.Register( public static readonly DependencyProperty BorderBrushProperty =
nameof(BorderBrush), typeof(Brush), typeof(PushpinBorder), DependencyPropertyHelper.Register<PushpinBorder, Brush>(nameof(BorderBrush), null,
new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender);
FrameworkPropertyMetadataOptions.AffectsRender));
public static readonly DependencyProperty CornerRadiusProperty = DependencyProperty.Register( public static readonly DependencyProperty CornerRadiusProperty =
nameof(CornerRadius), typeof(CornerRadius), typeof(PushpinBorder), DependencyPropertyHelper.Register<PushpinBorder, CornerRadius>(nameof(CornerRadius), new CornerRadius(),
new FrameworkPropertyMetadata(new CornerRadius(), FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender);
FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender));
public static readonly DependencyProperty PaddingProperty = DependencyProperty.Register( public static readonly DependencyProperty PaddingProperty =
nameof(Padding), typeof(Thickness), typeof(PushpinBorder), DependencyPropertyHelper.Register<PushpinBorder, Thickness>(nameof(Padding), new Thickness(2),
new FrameworkPropertyMetadata(new Thickness(2), FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender);
FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender));
public Brush Background public Brush Background
{ {

View file

@ -21,8 +21,8 @@ namespace MapControl
/// </summary> /// </summary>
public class Map : MapBase public class Map : MapBase
{ {
public static readonly DependencyProperty MouseWheelZoomDeltaProperty = DependencyProperty.Register( public static readonly DependencyProperty MouseWheelZoomDeltaProperty =
nameof(MouseWheelZoomDelta), typeof(double), typeof(Map), new PropertyMetadata(0.25)); DependencyPropertyHelper.Register<Map, double>(nameof(MouseWheelZoomDelta), 0.25);
private bool manipulationEnabled; private bool manipulationEnabled;
private double mouseWheelDelta; private double mouseWheelDelta;

View file

@ -17,13 +17,13 @@ namespace MapControl
/// </summary> /// </summary>
public class MapContentControl : ContentControl public class MapContentControl : ContentControl
{ {
public static readonly DependencyProperty AutoCollapseProperty = DependencyProperty.Register( public static readonly DependencyProperty AutoCollapseProperty =
nameof(AutoCollapse), typeof(bool), typeof(MapContentControl), DependencyPropertyHelper.Register<MapContentControl, bool>(nameof(AutoCollapse), false, false,
new PropertyMetadata(false, (o, e) => MapPanel.SetAutoCollapse((MapContentControl)o, (bool)e.NewValue))); (control, oldValue, newValue) => MapPanel.SetAutoCollapse(control, newValue));
public static readonly DependencyProperty LocationProperty = DependencyProperty.Register( public static readonly DependencyProperty LocationProperty =
nameof(Location), typeof(Location), typeof(MapContentControl), DependencyPropertyHelper.Register<MapContentControl, Location>(nameof(Location), null, false,
new PropertyMetadata(null, (o, e) => MapPanel.SetLocation((MapContentControl)o, (Location)e.NewValue))); (control, oldValue, newValue) => MapPanel.SetLocation(control, newValue));
public MapContentControl() public MapContentControl()
{ {

View file

@ -17,13 +17,13 @@ namespace MapControl
{ {
public partial class MapItem public partial class MapItem
{ {
public static readonly DependencyProperty AutoCollapseProperty = DependencyProperty.Register( public static readonly DependencyProperty AutoCollapseProperty =
nameof(AutoCollapse), typeof(bool), typeof(MapItem), new PropertyMetadata(false, DependencyPropertyHelper.Register<MapItem, bool>(nameof(AutoCollapse), false, false,
(o, e) => MapPanel.SetAutoCollapse((MapItem)o, (bool)e.NewValue))); (item, oldValue, newValue) => MapPanel.SetAutoCollapse(item, newValue));
public static readonly DependencyProperty LocationProperty = DependencyProperty.Register( public static readonly DependencyProperty LocationProperty =
nameof(Location), typeof(Location), typeof(MapItem), new PropertyMetadata(null, DependencyPropertyHelper.Register<MapItem, Location>(nameof(Location), null, false,
(o, e) => ((MapItem)o).LocationPropertyChanged((Location)e.NewValue))); (item, oldValue, newValue) => item.LocationPropertyChanged(newValue));
private void LocationPropertyChanged(Location location) private void LocationPropertyChanged(Location location)
{ {

View file

@ -16,50 +16,50 @@ namespace MapControl
{ {
public partial class MapOverlay public partial class MapOverlay
{ {
public static readonly DependencyProperty FontFamilyProperty = DependencyProperty.Register( public static readonly DependencyProperty FontFamilyProperty =
nameof(FontFamily), typeof(FontFamily), typeof(MapOverlay), new PropertyMetadata(null)); DependencyPropertyHelper.Register<MapOverlay, FontFamily>(nameof(FontFamily));
public static readonly DependencyProperty FontSizeProperty = DependencyProperty.Register( public static readonly DependencyProperty FontSizeProperty =
nameof(FontSize), typeof(double), typeof(MapOverlay), new PropertyMetadata(12d)); DependencyPropertyHelper.Register<MapOverlay, double>(nameof(FontSize), 12d);
public static readonly DependencyProperty FontStyleProperty = DependencyProperty.Register( public static readonly DependencyProperty FontStyleProperty =
nameof(FontStyle), typeof(FontStyle), typeof(MapOverlay), new PropertyMetadata(FontStyle.Normal)); DependencyPropertyHelper.Register<MapOverlay, FontStyle>(nameof(FontStyle), FontStyle.Normal);
public static readonly DependencyProperty FontStretchProperty = DependencyProperty.Register( public static readonly DependencyProperty FontStretchProperty =
nameof(FontStretch), typeof(FontStretch), typeof(MapOverlay), new PropertyMetadata(FontStretch.Normal)); DependencyPropertyHelper.Register<MapOverlay, FontStretch>(nameof(FontStretch), FontStretch.Normal);
public static readonly DependencyProperty FontWeightProperty = DependencyProperty.Register( public static readonly DependencyProperty FontWeightProperty =
nameof(FontWeight), typeof(FontWeight), typeof(MapOverlay), new PropertyMetadata(FontWeights.Normal)); DependencyPropertyHelper.Register<MapOverlay, FontWeight>(nameof(FontWeight), FontWeights.Normal);
public static readonly DependencyProperty ForegroundProperty = DependencyProperty.Register( public static readonly DependencyProperty ForegroundProperty =
nameof(Foreground), typeof(Brush), typeof(MapOverlay), new PropertyMetadata(null)); DependencyPropertyHelper.Register<MapOverlay, Brush>(nameof(Foreground));
public static readonly DependencyProperty StrokeProperty = DependencyProperty.Register( public static readonly DependencyProperty StrokeProperty =
nameof(Stroke), typeof(Brush), typeof(MapOverlay), new PropertyMetadata(null)); DependencyPropertyHelper.Register<MapOverlay, Brush>(nameof(Stroke));
public static readonly DependencyProperty StrokeThicknessProperty = DependencyProperty.Register( public static readonly DependencyProperty StrokeThicknessProperty =
nameof(StrokeThickness), typeof(double), typeof(MapOverlay), new PropertyMetadata(1d)); DependencyPropertyHelper.Register<MapOverlay, double>(nameof(StrokeThickness), 1d);
public static readonly DependencyProperty StrokeDashArrayProperty = DependencyProperty.Register( public static readonly DependencyProperty StrokeDashArrayProperty =
nameof(StrokeDashArray), typeof(DoubleCollection), typeof(MapOverlay), new PropertyMetadata(null)); DependencyPropertyHelper.Register<MapOverlay, DoubleCollection>(nameof(StrokeDashArray));
public static readonly DependencyProperty StrokeDashOffsetProperty = DependencyProperty.Register( public static readonly DependencyProperty StrokeDashOffsetProperty =
nameof(StrokeDashOffset), typeof(double), typeof(MapOverlay), new PropertyMetadata(0d)); DependencyPropertyHelper.Register<MapOverlay, double>(nameof(StrokeDashOffset));
public static readonly DependencyProperty StrokeDashCapProperty = DependencyProperty.Register( public static readonly DependencyProperty StrokeDashCapProperty =
nameof(StrokeDashCap), typeof(PenLineCap), typeof(MapOverlay), new PropertyMetadata(PenLineCap.Flat)); DependencyPropertyHelper.Register<MapOverlay, PenLineCap>(nameof(StrokeDashCap), PenLineCap.Flat);
public static readonly DependencyProperty StrokeStartLineCapProperty = DependencyProperty.Register( public static readonly DependencyProperty StrokeStartLineCapProperty =
nameof(StrokeStartLineCap), typeof(PenLineCap), typeof(MapOverlay), new PropertyMetadata(PenLineCap.Flat)); DependencyPropertyHelper.Register<MapOverlay, PenLineCap>(nameof(StrokeStartLineCap), PenLineCap.Flat);
public static readonly DependencyProperty StrokeEndLineCapProperty = DependencyProperty.Register( public static readonly DependencyProperty StrokeEndLineCapProperty =
nameof(StrokeEndLineCap), typeof(PenLineCap), typeof(MapOverlay), new PropertyMetadata(PenLineCap.Flat)); DependencyPropertyHelper.Register<MapOverlay, PenLineCap>(nameof(StrokeEndLineCap), PenLineCap.Flat);
public static readonly DependencyProperty StrokeLineJoinProperty = DependencyProperty.Register( public static readonly DependencyProperty StrokeLineJoinProperty =
nameof(StrokeLineJoin), typeof(PenLineJoin), typeof(MapOverlay), new PropertyMetadata(PenLineJoin.Miter)); DependencyPropertyHelper.Register<MapOverlay, PenLineJoin>(nameof(StrokeLineJoin), PenLineJoin.Miter);
public static readonly DependencyProperty StrokeMiterLimitProperty = DependencyProperty.Register( public static readonly DependencyProperty StrokeMiterLimitProperty =
nameof(StrokeMiterLimit), typeof(double), typeof(MapOverlay), new PropertyMetadata(1d)); DependencyPropertyHelper.Register<MapOverlay, double>(nameof(StrokeMiterLimit), 1d);
protected override void SetParentMap(MapBase map) protected override void SetParentMap(MapBase map)
{ {

View file

@ -2,6 +2,7 @@
// Copyright © 2024 Clemens Fischer // Copyright © 2024 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL) // Licensed under the Microsoft Public License (Ms-PL)
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Specialized; using System.Collections.Specialized;
using System.Linq; using System.Linq;
@ -39,14 +40,14 @@ namespace MapControl
#region Methods used only by derived classes MapPolyline and MapPolygon #region Methods used only by derived classes MapPolyline and MapPolygon
protected void DataCollectionPropertyChanged(DependencyPropertyChangedEventArgs e) protected void DataCollectionPropertyChanged(IEnumerable oldValue, IEnumerable newValue)
{ {
if (e.OldValue is INotifyCollectionChanged oldCollection) if (oldValue is INotifyCollectionChanged oldCollection)
{ {
oldCollection.CollectionChanged -= DataCollectionChanged; oldCollection.CollectionChanged -= DataCollectionChanged;
} }
if (e.NewValue is INotifyCollectionChanged newCollection) if (newValue is INotifyCollectionChanged newCollection)
{ {
newCollection.CollectionChanged += DataCollectionChanged; newCollection.CollectionChanged += DataCollectionChanged;
} }

View file

@ -24,13 +24,13 @@ namespace MapControl
[ContentProperty(Name = "Child")] [ContentProperty(Name = "Child")]
public partial class PushpinBorder : UserControl public partial class PushpinBorder : UserControl
{ {
public static readonly DependencyProperty ArrowSizeProperty = DependencyProperty.Register( public static readonly DependencyProperty ArrowSizeProperty =
nameof(ArrowSize), typeof(Size), typeof(PushpinBorder), DependencyPropertyHelper.Register<PushpinBorder, Size>(nameof(ArrowSize), new Size(10d, 20d), false,
new PropertyMetadata(new Size(10d, 20d), (o, e) => ((PushpinBorder)o).SetBorderMargin())); (border, oldValue, newValue) => border.SetBorderMargin());
public static readonly DependencyProperty BorderWidthProperty = DependencyProperty.Register( public static readonly DependencyProperty BorderWidthProperty =
nameof(BorderWidth), typeof(double), typeof(PushpinBorder), DependencyPropertyHelper.Register<PushpinBorder, double>(nameof(BorderWidth), 0d, false,
new PropertyMetadata(0d, (o, e) => ((PushpinBorder)o).SetBorderMargin())); (border, oldValue, newValue) => border.SetBorderMargin());
private readonly Border border = new Border(); private readonly Border border = new Border();

View file

@ -49,9 +49,9 @@ namespace MapControl.UiTools
((INotifyCollectionChanged)MapOverlays).CollectionChanged += (s, e) => InitializeMenu(); ((INotifyCollectionChanged)MapOverlays).CollectionChanged += (s, e) => InitializeMenu();
} }
public static readonly DependencyProperty MapProperty = DependencyProperty.Register( public static readonly DependencyProperty MapProperty =
nameof(Map), typeof(MapBase), typeof(MapLayersMenuButton), DependencyPropertyHelper.Register<MapLayersMenuButton, MapBase>(nameof(Map), null, false,
new PropertyMetadata(null, (o, e) => ((MapLayersMenuButton)o).InitializeMenu())); (button, oldValue, newValue) => button.InitializeMenu());
public MapBase Map public MapBase Map
{ {

View file

@ -44,9 +44,9 @@ namespace MapControl.UiTools
((INotifyCollectionChanged)MapProjections).CollectionChanged += (s, e) => InitializeMenu(); ((INotifyCollectionChanged)MapProjections).CollectionChanged += (s, e) => InitializeMenu();
} }
public static readonly DependencyProperty MapProperty = DependencyProperty.Register( public static readonly DependencyProperty MapProperty =
nameof(Map), typeof(MapBase), typeof(MapProjectionsMenuButton), DependencyPropertyHelper.Register<MapProjectionsMenuButton, MapBase>(nameof(Map), null, false,
new PropertyMetadata(null, (o, e) => ((MapProjectionsMenuButton)o).InitializeMenu())); (button, oldValue, newValue) => button.InitializeMenu());
public MapBase Map public MapBase Map
{ {