2013-05-25 08:53:50 +02:00
|
|
|
|
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
|
2016-02-23 20:07:30 +01:00
|
|
|
|
// © 2016 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(
|
2015-02-10 17:25:00 +01:00
|
|
|
|
"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
|
|
|
|
{
|
|
|
|
|
|
((MapPath)obj).UpdateData();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-02-18 19:20:59 +01:00
|
|
|
|
private static object CoerceDataProperty(DependencyObject obj, object value)
|
|
|
|
|
|
{
|
|
|
|
|
|
var data = (Geometry)value;
|
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
|
|
|
|
}
|
|
|
|
|
|
}
|