diff --git a/MapControl/MapBase.cs b/MapControl/MapBase.cs
index 0821bdcd..8ed125d3 100644
--- a/MapControl/MapBase.cs
+++ b/MapControl/MapBase.cs
@@ -108,6 +108,8 @@ namespace MapControl
public MapBase()
{
+ SetValue(MapPanel.ParentMapProperty, this);
+
Background = LightBackground;
TileLayers = new TileLayerCollection();
Initialize();
diff --git a/MapControl/MapControl.Silverlight.csproj b/MapControl/MapControl.Silverlight.csproj
index f2183a52..ef1131e5 100644
--- a/MapControl/MapControl.Silverlight.csproj
+++ b/MapControl/MapControl.Silverlight.csproj
@@ -76,10 +76,13 @@
+
+
+
@@ -88,6 +91,7 @@
+
diff --git a/MapControl/MapControl.WPF.csproj b/MapControl/MapControl.WPF.csproj
index 461cc10d..ff119bf9 100644
--- a/MapControl/MapControl.WPF.csproj
+++ b/MapControl/MapControl.WPF.csproj
@@ -62,6 +62,7 @@
+
diff --git a/MapControl/MapItem.Silverlight.WinRT.cs b/MapControl/MapItem.Silverlight.WinRT.cs
new file mode 100644
index 00000000..64945cb2
--- /dev/null
+++ b/MapControl/MapItem.Silverlight.WinRT.cs
@@ -0,0 +1,15 @@
+// XAML Map Control - http://xamlmapcontrol.codeplex.com/
+// Copyright © 2012 Clemens Fischer
+// Licensed under the Microsoft Public License (Ms-PL)
+
+namespace MapControl
+{
+ public partial class MapItem
+ {
+ public MapItem()
+ {
+ DefaultStyleKey = typeof(MapItem);
+ MapPanel.AddParentMapHandlers(this);
+ }
+ }
+}
diff --git a/MapControl/MapItem.cs b/MapControl/MapItem.cs
index a7dd0ce9..92a77e2d 100644
--- a/MapControl/MapItem.cs
+++ b/MapControl/MapItem.cs
@@ -22,12 +22,6 @@ namespace MapControl
public static readonly DependencyProperty LocationPathProperty = DependencyProperty.Register(
"LocationPath", typeof(string), typeof(MapItem), new PropertyMetadata(null, LocationPathPropertyChanged));
- public MapItem()
- {
- MapPanel.AddParentMapHandlers(this);
- DefaultStyleKey = typeof(MapItem);
- }
-
///
/// Gets or sets the property path that is used to bind the MapPanel.Location attached property.
///
diff --git a/MapControl/MapItemsControl.Silverlight.WinRT.cs b/MapControl/MapItemsControl.Silverlight.WinRT.cs
new file mode 100644
index 00000000..0d92d1be
--- /dev/null
+++ b/MapControl/MapItemsControl.Silverlight.WinRT.cs
@@ -0,0 +1,21 @@
+// XAML Map Control - http://xamlmapcontrol.codeplex.com/
+// Copyright © 2012 Clemens Fischer
+// Licensed under the Microsoft Public License (Ms-PL)
+
+#if WINRT
+using Windows.UI.Xaml;
+#else
+using System.Windows;
+#endif
+
+namespace MapControl
+{
+ public partial class MapItemsControl
+ {
+ public MapItemsControl()
+ {
+ DefaultStyleKey = typeof(MapItemsControl);
+ MapPanel.AddParentMapHandlers(this);
+ }
+ }
+}
\ No newline at end of file
diff --git a/MapControl/MapItemsControl.WPF.cs b/MapControl/MapItemsControl.WPF.cs
index 79b1c13c..2518ac66 100644
--- a/MapControl/MapItemsControl.WPF.cs
+++ b/MapControl/MapItemsControl.WPF.cs
@@ -19,7 +19,7 @@ namespace MapControl
typeof(MapItemsControl), new FrameworkPropertyMetadata(typeof(MapItemsControl)));
}
- partial void Initialize()
+ public MapItemsControl()
{
Items.CurrentChanging += OnCurrentItemChanging;
Items.CurrentChanged += OnCurrentItemChanged;
diff --git a/MapControl/MapItemsControl.cs b/MapControl/MapItemsControl.cs
index 6500d3b3..0415946c 100644
--- a/MapControl/MapItemsControl.cs
+++ b/MapControl/MapItemsControl.cs
@@ -18,20 +18,6 @@ namespace MapControl
///
public partial class MapItemsControl : ListBox
{
- public MapItemsControl()
- {
- MapPanel.AddParentMapHandlers(this);
- DefaultStyleKey = typeof(MapItemsControl);
- Initialize();
- }
-
- partial void Initialize();
-
- protected override DependencyObject GetContainerForItemOverride()
- {
- return new MapItem();
- }
-
public UIElement ContainerFromItem(object item)
{
return item != null ? ItemContainerGenerator.ContainerFromItem(item) as UIElement : null;
@@ -41,5 +27,10 @@ namespace MapControl
{
return container != null ? ItemContainerGenerator.ItemFromContainer(container) : null;
}
+
+ protected override DependencyObject GetContainerForItemOverride()
+ {
+ return new MapItem();
+ }
}
}
diff --git a/MapControl/MapOverlay.Silverlight.WinRT.cs b/MapControl/MapOverlay.Silverlight.WinRT.cs
index 7b3adaa0..8074d8db 100644
--- a/MapControl/MapOverlay.Silverlight.WinRT.cs
+++ b/MapControl/MapOverlay.Silverlight.WinRT.cs
@@ -81,8 +81,9 @@ namespace MapControl
protected readonly Path Path = new Path();
protected readonly PathGeometry Geometry = new PathGeometry();
- partial void Initialize()
+ public MapOverlay()
{
+ IsHitTestVisible = false;
Path.Stroke = Stroke;
Path.StrokeThickness = StrokeThickness;
Path.StrokeDashArray = StrokeDashArray;
diff --git a/MapControl/MapOverlay.WPF.cs b/MapControl/MapOverlay.WPF.cs
index 8176fb1e..3bd933fd 100644
--- a/MapControl/MapOverlay.WPF.cs
+++ b/MapControl/MapOverlay.WPF.cs
@@ -69,10 +69,8 @@ namespace MapControl
typeof(MapOverlay), new FrameworkPropertyMetadata(false));
}
- partial void Initialize()
+ public MapOverlay()
{
- MapPanel.AddParentMapHandlers(this);
-
pen = new Pen
{
Brush = Stroke,
diff --git a/MapControl/MapOverlay.cs b/MapControl/MapOverlay.cs
index e1ac0e6f..e1f5cc28 100644
--- a/MapControl/MapOverlay.cs
+++ b/MapControl/MapOverlay.cs
@@ -17,14 +17,6 @@ namespace MapControl
///
public partial class MapOverlay
{
- public MapOverlay()
- {
- IsHitTestVisible = false;
- Initialize();
- }
-
- partial void Initialize();
-
public FontFamily FontFamily
{
get { return (FontFamily)GetValue(FontFamilyProperty); }
diff --git a/MapControl/MapPanel.Silverlight.WinRT.cs b/MapControl/MapPanel.Silverlight.WinRT.cs
new file mode 100644
index 00000000..763269e3
--- /dev/null
+++ b/MapControl/MapPanel.Silverlight.WinRT.cs
@@ -0,0 +1,69 @@
+// XAML Map Control - http://xamlmapcontrol.codeplex.com/
+// Copyright © 2012 Clemens Fischer
+// Licensed under the Microsoft Public License (Ms-PL)
+
+#if WINRT
+using Windows.UI.Xaml;
+using Windows.UI.Xaml.Media;
+#else
+using System.Windows;
+using System.Windows.Media;
+#endif
+
+namespace MapControl
+{
+ public partial class MapPanel
+ {
+ public static readonly DependencyProperty ParentMapProperty = DependencyProperty.RegisterAttached(
+ "ParentMap", typeof(MapBase), typeof(MapPanel), new PropertyMetadata(null, ParentMapPropertyChanged));
+
+ public MapPanel()
+ {
+ if (!(this is MapBase))
+ {
+ AddParentMapHandlers(this);
+ }
+ }
+
+ ///
+ /// Helper method to work around missing property value inheritance in Silverlight and WinRT.
+ /// Adds Loaded and Unloaded handlers to the specified FrameworkElement, which set and clear
+ /// the value of the MapPanel.ParentMap attached property.
+ ///
+ public static void AddParentMapHandlers(FrameworkElement element)
+ {
+ element.Loaded += (o, e) => GetParentMap(element);
+ element.Unloaded += (o, e) => element.ClearValue(ParentMapProperty);
+ }
+
+ public static MapBase GetParentMap(UIElement element)
+ {
+ var parentMap = (MapBase)element.GetValue(ParentMapProperty);
+
+ if (parentMap == null && (parentMap = FindParentMap(element)) != null)
+ {
+ element.SetValue(ParentMapProperty, parentMap);
+ }
+
+ return parentMap;
+ }
+
+ private static MapBase FindParentMap(UIElement element)
+ {
+ MapBase parentMap = null;
+ var parentElement = VisualTreeHelper.GetParent(element) as UIElement;
+
+ if (parentElement != null)
+ {
+ parentMap = parentElement as MapBase;
+
+ if (parentMap == null)
+ {
+ parentMap = GetParentMap(parentElement);
+ }
+ }
+
+ return parentMap;
+ }
+ }
+}
diff --git a/MapControl/MapPanel.WPF.cs b/MapControl/MapPanel.WPF.cs
new file mode 100644
index 00000000..0f135839
--- /dev/null
+++ b/MapControl/MapPanel.WPF.cs
@@ -0,0 +1,20 @@
+// XAML Map Control - http://xamlmapcontrol.codeplex.com/
+// Copyright © 2012 Clemens Fischer
+// Licensed under the Microsoft Public License (Ms-PL)
+
+using System.Windows;
+
+namespace MapControl
+{
+ public partial class MapPanel
+ {
+ public static readonly DependencyProperty ParentMapProperty = DependencyProperty.RegisterAttached(
+ "ParentMap", typeof(MapBase), typeof(MapPanel),
+ new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.Inherits, ParentMapPropertyChanged));
+
+ public static MapBase GetParentMap(UIElement element)
+ {
+ return (MapBase)element.GetValue(ParentMapProperty);
+ }
+ }
+}
diff --git a/MapControl/MapPanel.cs b/MapControl/MapPanel.cs
index daabadb1..fa303776 100644
--- a/MapControl/MapPanel.cs
+++ b/MapControl/MapPanel.cs
@@ -26,30 +26,11 @@ namespace MapControl
/// The Location is transformed into a viewport position by the MapBase.LocationToViewportPoint
/// method and then applied to the RenderTransform as an appropriate TranslateTransform.
///
- public class MapPanel : Panel, IMapElement
+ public partial class MapPanel : Panel, IMapElement
{
- public static readonly DependencyProperty ParentMapProperty = DependencyProperty.RegisterAttached(
- "ParentMap", typeof(MapBase), typeof(MapPanel), new PropertyMetadata(null, ParentMapPropertyChanged));
-
public static readonly DependencyProperty LocationProperty = DependencyProperty.RegisterAttached(
"Location", typeof(Location), typeof(MapPanel), new PropertyMetadata(null, LocationPropertyChanged));
- public MapPanel()
- {
- AddParentMapHandlers(this);
- }
-
- public static void AddParentMapHandlers(FrameworkElement element)
- {
- element.Loaded += (o, e) => element.SetValue(ParentMapProperty, FindParentMap(element));
- element.Unloaded += (o, e) => element.ClearValue(ParentMapProperty);
- }
-
- public static MapBase GetParentMap(UIElement element)
- {
- return (MapBase)element.GetValue(ParentMapProperty);
- }
-
public static Location GetLocation(UIElement element)
{
return (Location)element.GetValue(LocationProperty);
@@ -83,8 +64,8 @@ namespace MapControl
SetViewportPosition(element, parentMap, location);
}
- var frameworkElement = element as FrameworkElement;
var rect = new Rect(0d, 0d, element.DesiredSize.Width, element.DesiredSize.Height);
+ var frameworkElement = element as FrameworkElement;
if (frameworkElement != null)
{
@@ -171,11 +152,6 @@ namespace MapControl
}
}
- private static MapBase FindParentMap(DependencyObject obj)
- {
- return (obj == null || obj is MapBase) ? (MapBase)obj : FindParentMap(VisualTreeHelper.GetParent(obj));
- }
-
private static void ParentMapPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
{
var element = obj as IMapElement;
diff --git a/MapControl/MapPolyline.Silverlight.cs b/MapControl/MapPolyline.Silverlight.cs
index 537eb880..1eb149e0 100644
--- a/MapControl/MapPolyline.Silverlight.cs
+++ b/MapControl/MapPolyline.Silverlight.cs
@@ -2,7 +2,6 @@
// Copyright © 2012 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
-using System;
using System.Windows;
using System.Windows.Shapes;
@@ -10,16 +9,17 @@ namespace MapControl
{
public partial class MapPolyline : Path
{
- partial void Initialize()
+ public MapPolyline()
{
Data = Geometry;
+ MapPanel.AddParentMapHandlers(this);
}
protected override Size MeasureOverride(Size constraint)
{
- return new Size(
- Math.Max(Geometry.Bounds.Width, Geometry.Bounds.Right),
- Math.Max(Geometry.Bounds.Height, Geometry.Bounds.Bottom));
+ // MeasureOverride in Silverlight occasionally tries to create
+ // negative width or height from a transformed geometry in Data.
+ return new Size(Geometry.Bounds.Width, Geometry.Bounds.Height);
}
}
}
diff --git a/MapControl/MapPolyline.WinRT.cs b/MapControl/MapPolyline.WinRT.cs
index 52a0c817..7248276a 100644
--- a/MapControl/MapPolyline.WinRT.cs
+++ b/MapControl/MapPolyline.WinRT.cs
@@ -8,9 +8,10 @@ namespace MapControl
{
public partial class MapPolyline : Path
{
- partial void Initialize()
+ public MapPolyline()
{
Data = Geometry;
+ MapPanel.AddParentMapHandlers(this);
}
}
}
diff --git a/MapControl/MapPolyline.cs b/MapControl/MapPolyline.cs
index df81a5ce..c3be1440 100644
--- a/MapControl/MapPolyline.cs
+++ b/MapControl/MapPolyline.cs
@@ -21,14 +21,6 @@ namespace MapControl
protected PathGeometry Geometry = new PathGeometry();
- public MapPolyline()
- {
- MapPanel.AddParentMapHandlers(this);
- Initialize();
- }
-
- partial void Initialize();
-
public LocationCollection Locations
{
get { return (LocationCollection)GetValue(LocationsProperty); }
diff --git a/MapControl/Pushpin.Silverlight.WinRT.cs b/MapControl/Pushpin.Silverlight.WinRT.cs
new file mode 100644
index 00000000..883ead5a
--- /dev/null
+++ b/MapControl/Pushpin.Silverlight.WinRT.cs
@@ -0,0 +1,15 @@
+// XAML Map Control - http://xamlmapcontrol.codeplex.com/
+// Copyright © 2012 Clemens Fischer
+// Licensed under the Microsoft Public License (Ms-PL)
+
+namespace MapControl
+{
+ public partial class Pushpin
+ {
+ public Pushpin()
+ {
+ DefaultStyleKey = typeof(Pushpin);
+ MapPanel.AddParentMapHandlers(this);
+ }
+ }
+}
diff --git a/MapControl/Pushpin.cs b/MapControl/Pushpin.cs
index 7d48eb8c..c64948bb 100644
--- a/MapControl/Pushpin.cs
+++ b/MapControl/Pushpin.cs
@@ -22,12 +22,6 @@ namespace MapControl
public static readonly DependencyProperty LocationPathProperty = DependencyProperty.Register(
"LocationPath", typeof(string), typeof(Pushpin), new PropertyMetadata(null, LocationPathPropertyChanged));
- public Pushpin()
- {
- MapPanel.AddParentMapHandlers(this);
- DefaultStyleKey = typeof(Pushpin);
- }
-
///
/// Gets or sets the property path that is used to bind the MapPanel.Location attached property.
///
diff --git a/MapControl/WinRT/MapControl.WinRT.csproj b/MapControl/WinRT/MapControl.WinRT.csproj
index 2f4ad534..dbd75e8f 100644
--- a/MapControl/WinRT/MapControl.WinRT.csproj
+++ b/MapControl/WinRT/MapControl.WinRT.csproj
@@ -132,9 +132,15 @@
MapItem.cs
+
+ MapItem.Silverlight.WinRT.cs
+
MapItemsControl.cs
+
+ MapItemsControl.Silverlight.WinRT.cs
+
MapOverlay.cs
@@ -144,6 +150,9 @@
MapPanel.cs
+
+ MapPanel.Silverlight.WinRT.cs
+
MapPolygon.cs
@@ -165,6 +174,9 @@
Pushpin.cs
+
+ Pushpin.Silverlight.WinRT.cs
+
Tile.cs