// XAML Map Control - http://xamlmapcontrol.codeplex.com/ // Copyright © Clemens Fischer 2012-2013 // Licensed under the Microsoft Public License (Ms-PL) using System; using System.Collections.Generic; using System.Collections.Specialized; #if NETFX_CORE using Windows.Foundation; using Windows.UI.Xaml; #else using System.Windows; using System.ComponentModel; #endif namespace MapControl { public partial class MapPolyline : MapPath { #if NETFX_CORE // For WinRT, the Locations dependency property type is declared as object // instead of IEnumerable. See http://stackoverflow.com/q/10544084/1136211 private static readonly Type LocationsPropertyType = typeof(object); #else private static readonly Type LocationsPropertyType = typeof(IEnumerable); #endif public static readonly DependencyProperty LocationsProperty = DependencyProperty.Register( "Locations", LocationsPropertyType, typeof(MapPolyline), new PropertyMetadata(null, LocationsPropertyChanged)); public static readonly DependencyProperty IsClosedProperty = DependencyProperty.Register( "IsClosed", typeof(bool), typeof(MapPolyline), new PropertyMetadata(false, (o, e) => ((MapPolyline)o).UpdateData())); /// /// Gets or sets the locations that define the polyline points. /// #if !NETFX_CORE [TypeConverter(typeof(LocationCollectionConverter))] #endif public IEnumerable Locations { get { return (IEnumerable)GetValue(LocationsProperty); } set { SetValue(LocationsProperty, value); } } /// /// Gets or sets a value that indicates if the polyline is closed, i.e. is a polygon. /// public bool IsClosed { get { return (bool)GetValue(IsClosedProperty); } set { SetValue(IsClosedProperty, value); } } private void LocationCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { UpdateData(); } private static void LocationsPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) { var mapPolyline = (MapPolyline)obj; var oldCollection = e.OldValue as INotifyCollectionChanged; var newCollection = e.NewValue as INotifyCollectionChanged; if (oldCollection != null) { oldCollection.CollectionChanged -= mapPolyline.LocationCollectionChanged; } if (newCollection != null) { newCollection.CollectionChanged += mapPolyline.LocationCollectionChanged; } mapPolyline.UpdateData(); } } }