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

57 lines
2.1 KiB
C#
Raw 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
2026-04-13 17:14:49 +02:00
namespace MapControl;
public partial class MapPanel
{
2026-04-13 17:14:49 +02:00
public static readonly DependencyProperty AutoCollapseProperty =
DependencyPropertyHelper.RegisterAttached<bool>("AutoCollapse", typeof(MapPanel));
2024-05-27 11:05:22 +02:00
2026-04-13 17:14:49 +02:00
public static readonly DependencyProperty LocationProperty =
DependencyPropertyHelper.RegisterAttached<Location>("Location", typeof(MapPanel), null,
(element, oldValue, newValue) => (element.Parent as MapPanel)?.InvalidateArrange());
2024-05-27 11:05:22 +02:00
2026-04-13 17:14:49 +02:00
public static readonly DependencyProperty BoundingBoxProperty =
DependencyPropertyHelper.RegisterAttached<BoundingBox>("BoundingBox", typeof(MapPanel), null,
(element, oldValue, newValue) => (element.Parent as MapPanel)?.InvalidateArrange());
2024-05-27 11:05:22 +02:00
2026-04-13 17:14:49 +02:00
public static readonly DependencyProperty MapRectProperty =
DependencyPropertyHelper.RegisterAttached<Rect?>("MapRect", typeof(MapPanel), null,
(element, oldValue, newValue) => (element.Parent as MapPanel)?.InvalidateArrange());
2026-01-28 15:55:30 +01:00
2026-04-13 17:14:49 +02:00
public static void InitMapElement(FrameworkElement element)
{
// Workaround for missing property value inheritance.
// Loaded and Unloaded handlers set and clear the ParentMap property value.
//
element.Loaded += (_, _) => GetParentMap(element);
element.Unloaded += (_, _) => element.ClearValue(ParentMapProperty);
}
2026-04-13 17:14:49 +02:00
public static MapBase GetParentMap(FrameworkElement element)
{
var parentMap = (MapBase)element.GetValue(ParentMapProperty);
// Traverse visual tree because of missing property value inheritance.
//
if (parentMap == null &&
VisualTreeHelper.GetParent(element) is FrameworkElement parentElement)
{
2026-04-13 17:14:49 +02:00
parentMap = (parentElement as MapBase) ?? GetParentMap(parentElement);
2026-04-13 17:14:49 +02:00
if (parentMap != null)
{
2026-04-13 17:14:49 +02:00
element.SetValue(ParentMapProperty, parentMap);
}
}
2026-04-13 17:14:49 +02:00
return parentMap;
}
}