XAML-Map-Control/MapControl/MapPolyline.cs

93 lines
3.2 KiB
C#
Raw Normal View History

// XAML Map Control - http://xamlmapcontrol.codeplex.com/
2015-01-20 17:52:02 +01:00
// © 2015 Clemens Fischer
2012-05-04 12:52:20 +02:00
// Licensed under the Microsoft Public License (Ms-PL)
2012-12-15 18:54:40 +01:00
using System.Collections.Generic;
using System.Collections.Specialized;
#if WINDOWS_RUNTIME
using System.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Media;
#else
using System.ComponentModel;
using System.Windows;
using System.Windows.Media;
#endif
2012-04-25 22:02:53 +02:00
namespace MapControl
{
/// <summary>
/// A polyline or polygon created from a collection of Locations.
/// </summary>
public partial class MapPolyline : MapPath
2012-04-25 22:02:53 +02:00
{
#if WINDOWS_RUNTIME
// Binding fails on Windows Phone when property type is IEnumerable<Location>
public static readonly DependencyProperty LocationsProperty = DependencyProperty.Register(
"Locations", typeof(IEnumerable), typeof(MapPolyline),
new PropertyMetadata(null, LocationsPropertyChanged));
#else
public static readonly DependencyProperty LocationsProperty = DependencyProperty.Register(
"Locations", typeof(IEnumerable<Location>), typeof(MapPolyline),
new PropertyMetadata(null, LocationsPropertyChanged));
#endif
public static readonly DependencyProperty IsClosedProperty = DependencyProperty.Register(
"IsClosed", typeof(bool), typeof(MapPolyline),
new PropertyMetadata(false, (o, e) => ((MapPolyline)o).UpdateData()));
2012-04-25 22:02:53 +02:00
/// <summary>
/// Gets or sets the locations that define the polyline points.
/// </summary>
#if !WINDOWS_RUNTIME
[TypeConverter(typeof(LocationCollectionConverter))]
#endif
2012-12-15 18:54:40 +01:00
public IEnumerable<Location> Locations
2012-05-04 12:52:20 +02:00
{
2012-12-15 18:54:40 +01:00
get { return (IEnumerable<Location>)GetValue(LocationsProperty); }
2012-05-04 12:52:20 +02:00
set { SetValue(LocationsProperty, value); }
}
/// <summary>
/// Gets or sets a value that indicates if the polyline is closed, i.e. is a polygon.
/// </summary>
public bool IsClosed
2012-05-04 12:52:20 +02:00
{
get { return (bool)GetValue(IsClosedProperty); }
set { SetValue(IsClosedProperty, value); }
2012-04-25 22:02:53 +02:00
}
2012-05-04 12:52:20 +02:00
/// <summary>
/// Gets or sets the FillRule of the PathGeometry that represents the polyline.
/// </summary>
public FillRule FillRule
{
get { return (FillRule)GetValue(FillRuleProperty); }
set { SetValue(FillRuleProperty, value); }
}
2012-12-15 18:54:40 +01:00
private void LocationCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
UpdateData();
2012-12-15 18:54:40 +01:00
}
private static void LocationsPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
{
var mapPolyline = (MapPolyline)obj;
2012-12-15 19:11:54 +01:00
var oldCollection = e.OldValue as INotifyCollectionChanged;
var newCollection = e.NewValue as INotifyCollectionChanged;
2012-12-15 18:54:40 +01:00
2012-12-15 19:11:54 +01:00
if (oldCollection != null)
2012-12-15 18:54:40 +01:00
{
2012-12-15 19:11:54 +01:00
oldCollection.CollectionChanged -= mapPolyline.LocationCollectionChanged;
2012-12-15 18:54:40 +01:00
}
2012-12-15 19:11:54 +01:00
if (newCollection != null)
2012-12-15 18:54:40 +01:00
{
2012-12-15 19:11:54 +01:00
newCollection.CollectionChanged += mapPolyline.LocationCollectionChanged;
2012-12-15 18:54:40 +01:00
}
mapPolyline.UpdateData();
2012-12-15 18:54:40 +01:00
}
2012-04-25 22:02:53 +02:00
}
}