diff --git a/MapControl/Map.cs b/MapControl/Map.cs index fa94e370..65a38688 100644 --- a/MapControl/Map.cs +++ b/MapControl/Map.cs @@ -42,7 +42,8 @@ namespace MapControl public static readonly DependencyProperty TileLayersProperty = DependencyProperty.Register( "TileLayers", typeof(TileLayerCollection), typeof(Map), new FrameworkPropertyMetadata( - (o, e) => ((Map)o).TileLayersPropertyChanged((TileLayerCollection)e.NewValue))); + (o, e) => ((Map)o).TileLayersPropertyChanged((TileLayerCollection)e.NewValue), + (o, v) => ((Map)o).CoerceTileLayersProperty((TileLayerCollection)v))); public static readonly DependencyProperty MainTileLayerProperty = DependencyProperty.Register( "MainTileLayer", typeof(TileLayer), typeof(Map), new FrameworkPropertyMetadata( @@ -105,6 +106,7 @@ namespace MapControl MinZoomLevel = 1; MaxZoomLevel = 20; AddVisualChild(tileContainer); + TileLayers = new TileLayerCollection(); SetValue(ParentMapProperty, this); } @@ -483,19 +485,28 @@ namespace MapControl private void TileLayersPropertyChanged(TileLayerCollection tileLayers) { - tileContainer.TileLayers = tileLayers; - MainTileLayer = tileLayers.Count > 0 ? tileLayers[0] : null; + if (tileLayers != null) + { + tileContainer.TileLayers = tileLayers; + MainTileLayer = tileLayers.Count > 0 ? tileLayers[0] : null; + } + } + + private TileLayerCollection CoerceTileLayersProperty(TileLayerCollection tileLayers) + { + if (tileLayers == null) + { + tileLayers = new TileLayerCollection(); + } + + return tileLayers; } private void MainTileLayerPropertyChanged(TileLayer mainTileLayer) { if (mainTileLayer != null) { - if (tileContainer.TileLayers == null) - { - TileLayers = new TileLayerCollection(mainTileLayer); - } - else if (tileContainer.TileLayers.Count == 0) + if (tileContainer.TileLayers.Count == 0) { tileContainer.TileLayers.Add(mainTileLayer); } @@ -508,7 +519,7 @@ namespace MapControl private TileLayer CoerceMainTileLayerProperty(TileLayer mainTileLayer) { - if (mainTileLayer == null && tileContainer.TileLayers != null && tileContainer.TileLayers.Count > 0) + if (mainTileLayer == null && tileContainer.TileLayers.Count > 0) { mainTileLayer = tileContainer.TileLayers[0]; } diff --git a/MapControl/MapControl.csproj b/MapControl/MapControl.csproj index b3971fd7..5f6c4dea 100644 --- a/MapControl/MapControl.csproj +++ b/MapControl/MapControl.csproj @@ -53,6 +53,7 @@ + diff --git a/MapControl/MapItem.cs b/MapControl/MapItem.cs index e644b515..7ea31070 100644 --- a/MapControl/MapItem.cs +++ b/MapControl/MapItem.cs @@ -36,11 +36,11 @@ namespace MapControl static MapItem() { - FrameworkElement.DefaultStyleKeyProperty.OverrideMetadata(typeof(MapItem), - new FrameworkPropertyMetadata(typeof(MapItem))); + FrameworkElement.DefaultStyleKeyProperty.OverrideMetadata( + typeof(MapItem), new FrameworkPropertyMetadata(typeof(MapItem))); - UIElement.IsEnabledProperty.OverrideMetadata(typeof(MapItem), - new FrameworkPropertyMetadata((o, e) => ((MapItem)o).CommonStateChanged())); + UIElement.IsEnabledProperty.OverrideMetadata( + typeof(MapItem), new FrameworkPropertyMetadata((o, e) => ((MapItem)o).CommonStateChanged())); } public event RoutedEventHandler Selected diff --git a/MapControl/Pushpin.cs b/MapControl/Pushpin.cs new file mode 100644 index 00000000..745f7ce2 --- /dev/null +++ b/MapControl/Pushpin.cs @@ -0,0 +1,29 @@ +using System; +using System.Windows; +using System.Windows.Controls; + +namespace MapControl +{ + /// + /// Displays a pushpin at the geographic location provided by the Location property. + /// + [TemplateVisualState(Name = "Normal", GroupName = "CommonStates")] + [TemplateVisualState(Name = "MouseOver", GroupName = "CommonStates")] + [TemplateVisualState(Name = "Disabled", GroupName = "CommonStates")] + public class Pushpin : ContentControl + { + public static readonly DependencyProperty LocationProperty = MapPanel.LocationProperty.AddOwner(typeof(Pushpin)); + + static Pushpin() + { + FrameworkElement.DefaultStyleKeyProperty.OverrideMetadata( + typeof(Pushpin), new FrameworkPropertyMetadata(typeof(Pushpin))); + } + + public Location Location + { + get { return (Location)GetValue(LocationProperty); } + set { SetValue(LocationProperty, value); } + } + } +} diff --git a/MapControl/Themes/Generic.xaml b/MapControl/Themes/Generic.xaml index eb352ed3..1409c6d7 100644 --- a/MapControl/Themes/Generic.xaml +++ b/MapControl/Themes/Generic.xaml @@ -11,6 +11,20 @@ +