2017-06-25 23:05:48 +02:00
|
|
|
|
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
|
|
|
|
|
// © 2017 Clemens Fischer
|
2013-05-25 08:53:50 +02:00
|
|
|
|
// Licensed under the Microsoft Public License (Ms-PL)
|
|
|
|
|
|
|
|
|
|
|
|
using System.Windows;
|
|
|
|
|
|
using System.Windows.Media;
|
|
|
|
|
|
using System.Windows.Shapes;
|
|
|
|
|
|
|
|
|
|
|
|
namespace MapControl
|
|
|
|
|
|
{
|
|
|
|
|
|
public partial class MapPath : Shape
|
|
|
|
|
|
{
|
|
|
|
|
|
public static readonly DependencyProperty DataProperty = DependencyProperty.Register(
|
2017-06-25 23:05:48 +02:00
|
|
|
|
nameof(Data), typeof(Geometry), typeof(MapPath), new FrameworkPropertyMetadata(
|
2016-08-08 20:36:02 +02:00
|
|
|
|
null, FrameworkPropertyMetadataOptions.AffectsRender, DataPropertyChanged, CoerceDataProperty));
|
2015-02-18 19:20:59 +01:00
|
|
|
|
|
|
|
|
|
|
static MapPath()
|
|
|
|
|
|
{
|
|
|
|
|
|
StretchProperty.OverrideMetadata(typeof(MapPath),
|
|
|
|
|
|
new FrameworkPropertyMetadata { CoerceValueCallback = (o, v) => Stretch.None });
|
|
|
|
|
|
}
|
2013-05-25 08:53:50 +02:00
|
|
|
|
|
|
|
|
|
|
public Geometry Data
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return (Geometry)GetValue(DataProperty); }
|
|
|
|
|
|
set { SetValue(DataProperty, value); }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override Geometry DefiningGeometry
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return Data; }
|
|
|
|
|
|
}
|
2015-02-10 21:59:39 +01:00
|
|
|
|
|
|
|
|
|
|
protected override Size MeasureOverride(Size constraint)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Shape.MeasureOverride sometimes returns an empty Size.
|
|
|
|
|
|
return new Size(1, 1);
|
|
|
|
|
|
}
|
2015-02-18 19:20:59 +01:00
|
|
|
|
|
2016-04-19 19:36:03 +02:00
|
|
|
|
private static void DataPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
|
|
|
|
|
|
{
|
2016-08-08 20:36:02 +02:00
|
|
|
|
if (!ReferenceEquals(e.OldValue, e.NewValue))
|
2016-04-19 19:36:03 +02:00
|
|
|
|
{
|
2017-06-25 23:05:48 +02:00
|
|
|
|
var mapPath = (MapPath)obj;
|
|
|
|
|
|
|
|
|
|
|
|
if (e.OldValue != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
((Geometry)e.OldValue).ClearValue(Geometry.TransformProperty);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (e.NewValue != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
((Geometry)e.NewValue).Transform = mapPath.viewportTransform;
|
|
|
|
|
|
}
|
2016-04-19 19:36:03 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-02-18 19:20:59 +01:00
|
|
|
|
private static object CoerceDataProperty(DependencyObject obj, object value)
|
|
|
|
|
|
{
|
|
|
|
|
|
var data = (Geometry)value;
|
2017-06-25 23:05:48 +02:00
|
|
|
|
|
2016-04-19 19:36:03 +02:00
|
|
|
|
return (data != null && data.IsFrozen) ? data.CloneCurrentValue() : data;
|
2015-02-18 19:20:59 +01:00
|
|
|
|
}
|
2013-05-25 08:53:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|