mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-05-07 13:37:47 +00:00
Version 4: Upgrade to VS 2017
This commit is contained in:
parent
2aafe32e00
commit
ec47f225b3
142 changed files with 1828 additions and 18384 deletions
68
MapControl/UWP/MapPanel.UWP.cs
Normal file
68
MapControl/UWP/MapPanel.UWP.cs
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
||||
// © 2017 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Media;
|
||||
|
||||
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)
|
||||
{
|
||||
SetValue(ParentMapProperty, this);
|
||||
}
|
||||
else
|
||||
{
|
||||
AddParentMapHandlers(this);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper method to work around missing property value inheritance in Silverlight and Windows Runtime.
|
||||
/// Adds Loaded and Unloaded event handlers to the specified FrameworkElement, which set and clear the
|
||||
/// value of the MapPanel.ParentMap attached property.
|
||||
/// </summary>
|
||||
public static void AddParentMapHandlers(FrameworkElement element)
|
||||
{
|
||||
element.Loaded += (s, e) => GetParentMap(element);
|
||||
element.Unloaded += (s, 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue