From 71e7e292005e7bca812847ebe0a0d79139bd8521 Mon Sep 17 00:00:00 2001 From: ClemensFischer Date: Tue, 10 Jun 2025 23:50:58 +0200 Subject: [PATCH] MapPanel constructor --- MapControl/Avalonia/MapPanel.Avalonia.cs | 8 -------- MapControl/Shared/MapPanel.cs | 16 ++++++++++++++++ MapControl/WPF/MapPanel.WPF.cs | 8 -------- MapControl/WinUI/MapPanel.WinUI.cs | 20 ++++++-------------- 4 files changed, 22 insertions(+), 30 deletions(-) diff --git a/MapControl/Avalonia/MapPanel.Avalonia.cs b/MapControl/Avalonia/MapPanel.Avalonia.cs index 9500369b..f8c9fb37 100644 --- a/MapControl/Avalonia/MapPanel.Avalonia.cs +++ b/MapControl/Avalonia/MapPanel.Avalonia.cs @@ -18,14 +18,6 @@ AffectsParentArrange(LocationProperty, BoundingBoxProperty); } - public MapPanel() - { - if (this is MapBase) - { - SetValue(ParentMapProperty, this); - } - } - public static MapBase GetParentMap(Control element) { return (MapBase)element.GetValue(ParentMapProperty); diff --git a/MapControl/Shared/MapPanel.cs b/MapControl/Shared/MapPanel.cs index d5a3cdc1..7cfb4ad9 100644 --- a/MapControl/Shared/MapPanel.cs +++ b/MapControl/Shared/MapPanel.cs @@ -44,6 +44,22 @@ namespace MapControl }, true); // inherits + public MapPanel() + { + UseLayoutRounding = false; + + if (this is MapBase) + { + SetValue(ParentMapProperty, this); + } + else + { + InitMapPanel(); + } + } + + partial void InitMapPanel(); + private MapBase parentMap; /// diff --git a/MapControl/WPF/MapPanel.WPF.cs b/MapControl/WPF/MapPanel.WPF.cs index 319b5e6a..fd7683fe 100644 --- a/MapControl/WPF/MapPanel.WPF.cs +++ b/MapControl/WPF/MapPanel.WPF.cs @@ -20,14 +20,6 @@ namespace MapControl protected IEnumerable ChildElements => InternalChildren.OfType(); - public MapPanel() - { - if (this is MapBase) - { - SetValue(ParentMapProperty, this); - } - } - public static MapBase GetParentMap(FrameworkElement element) { return (MapBase)element.GetValue(ParentMapProperty); diff --git a/MapControl/WinUI/MapPanel.WinUI.cs b/MapControl/WinUI/MapPanel.WinUI.cs index 1818a7b7..b679a3ba 100644 --- a/MapControl/WinUI/MapPanel.WinUI.cs +++ b/MapControl/WinUI/MapPanel.WinUI.cs @@ -25,26 +25,18 @@ namespace MapControl protected IEnumerable ChildElements => Children.OfType(); - public MapPanel() + partial void InitMapPanel() { - UseLayoutRounding = false; InitMapElement(this); } public static void InitMapElement(FrameworkElement element) { - if (element is MapBase) - { - element.SetValue(ParentMapProperty, element); - } - else - { - // 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); - } + // 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)