XAML-Map-Control/MapControl/WinUI/MapPanel.WinUI.cs

54 lines
2 KiB
C#
Raw Permalink Normal View History

2025-08-12 11:33:39 +02:00
#if UWP
using Windows.UI.Xaml;
using Windows.UI.Xaml.Media;
2024-05-22 11:25:32 +02:00
#else
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Media;
2021-06-14 21:41:37 +02:00
#endif
namespace MapControl
{
public partial class MapPanel
{
2024-05-27 11:05:22 +02:00
public static readonly DependencyProperty AutoCollapseProperty =
DependencyPropertyHelper.RegisterAttached<bool>("AutoCollapse", typeof(MapPanel));
2024-05-27 11:05:22 +02:00
public static readonly DependencyProperty LocationProperty =
DependencyPropertyHelper.RegisterAttached<Location>("Location", typeof(MapPanel), null,
2024-05-27 11:05:22 +02:00
(element, oldValue, newValue) => (element.Parent as MapPanel)?.InvalidateArrange());
public static readonly DependencyProperty BoundingBoxProperty =
DependencyPropertyHelper.RegisterAttached<BoundingBox>("BoundingBox", typeof(MapPanel), null,
2024-05-27 11:05:22 +02:00
(element, oldValue, newValue) => (element.Parent as MapPanel)?.InvalidateArrange());
2017-09-05 20:57:17 +02:00
public static void InitMapElement(FrameworkElement element)
{
2025-06-10 23:50:58 +02:00
// Workaround for missing property value inheritance.
// Loaded and Unloaded handlers set and clear the ParentMap property value.
//
element.Loaded += (s, e) => GetParentMap((FrameworkElement)s);
element.Unloaded += (s, e) => ((FrameworkElement)s).ClearValue(ParentMapProperty);
}
public static MapBase GetParentMap(FrameworkElement element)
{
var parentMap = (MapBase)element.GetValue(ParentMapProperty);
2024-05-20 23:24:34 +02:00
// Traverse visual tree because of missing property value inheritance.
2025-03-24 23:20:32 +01:00
//
2022-08-02 19:54:14 +02:00
if (parentMap == null &&
VisualTreeHelper.GetParent(element) is FrameworkElement parentElement)
{
2022-08-02 19:50:11 +02:00
parentMap = (parentElement as MapBase) ?? GetParentMap(parentElement);
if (parentMap != null)
{
element.SetValue(ParentMapProperty, parentMap);
}
}
return parentMap;
}
}
}