2017-06-25 23:05:48 +02:00
|
|
|
|
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
|
|
|
|
|
// © 2017 Clemens Fischer
|
2012-11-23 16:16:09 +01:00
|
|
|
|
// Licensed under the Microsoft Public License (Ms-PL)
|
|
|
|
|
|
|
2015-08-09 20:04:44 +02:00
|
|
|
|
#if NETFX_CORE
|
2012-11-23 16:16:09 +01:00
|
|
|
|
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()
|
|
|
|
|
|
{
|
2014-11-19 21:11:14 +01:00
|
|
|
|
if (this is MapBase)
|
|
|
|
|
|
{
|
|
|
|
|
|
SetValue(ParentMapProperty, this);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
2012-11-23 16:16:09 +01:00
|
|
|
|
{
|
|
|
|
|
|
AddParentMapHandlers(this);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2014-07-01 18:57:44 +02:00
|
|
|
|
/// Helper method to work around missing property value inheritance in Silverlight and Windows Runtime.
|
2015-11-11 19:48:50 +01:00
|
|
|
|
/// Adds Loaded and Unloaded event handlers to the specified FrameworkElement, which set and clear the
|
|
|
|
|
|
/// value of the MapPanel.ParentMap attached property.
|
2012-11-23 16:16:09 +01:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static void AddParentMapHandlers(FrameworkElement element)
|
|
|
|
|
|
{
|
2014-06-11 23:03:13 +02:00
|
|
|
|
element.Loaded += (s, e) => GetParentMap(element);
|
|
|
|
|
|
element.Unloaded += (s, e) => element.ClearValue(ParentMapProperty);
|
2012-11-23 16:16:09 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|