From b7afd27c91141faf3f3e8bde30783a90cbca2d35 Mon Sep 17 00:00:00 2001 From: ClemensFischer Date: Thu, 23 May 2024 19:21:28 +0200 Subject: [PATCH] DependencyPropertyHelper --- MBTiles/Shared/MBTileLayer.cs | 2 +- .../DependencyPropertyHelper.Avalonia.cs | 4 ++-- MapControl/Shared/MapPanel.cs | 22 ++++++++++--------- .../WPF/DependencyPropertyHelper.WPF.cs | 4 ++-- .../WinUI/DependencyPropertyHelper.WinUI.cs | 4 ++-- MapUiTools/Shared/MapLayersMenuButton.cs | 2 +- MapUiTools/Shared/MapProjectionsMenuButton.cs | 2 +- 7 files changed, 21 insertions(+), 19 deletions(-) diff --git a/MBTiles/Shared/MBTileLayer.cs b/MBTiles/Shared/MBTileLayer.cs index f6060a42..caf59695 100644 --- a/MBTiles/Shared/MBTileLayer.cs +++ b/MBTiles/Shared/MBTileLayer.cs @@ -19,7 +19,7 @@ namespace MapControl.MBTiles public class MBTileLayer : MapTileLayer { public static readonly DependencyProperty FileProperty = - DependencyPropertyHelper.Register(nameof(File), null, false, + DependencyPropertyHelper.Register(nameof(File), null, async (layer, oldValue, newValue) => await layer.FilePropertyChanged(newValue)); public string File diff --git a/MapControl/Avalonia/DependencyPropertyHelper.Avalonia.cs b/MapControl/Avalonia/DependencyPropertyHelper.Avalonia.cs index b8178130..371280f6 100644 --- a/MapControl/Avalonia/DependencyPropertyHelper.Avalonia.cs +++ b/MapControl/Avalonia/DependencyPropertyHelper.Avalonia.cs @@ -31,8 +31,8 @@ namespace MapControl public static AttachedProperty RegisterAttached( string name, TValue defaultValue = default, - bool inherits = false, - Action changed = null) + Action changed = null, + bool inherits = false) where TOwner : AvaloniaObject { var property = AvaloniaProperty.RegisterAttached(name, defaultValue, inherits); diff --git a/MapControl/Shared/MapPanel.cs b/MapControl/Shared/MapPanel.cs index 18da0858..19dab542 100644 --- a/MapControl/Shared/MapPanel.cs +++ b/MapControl/Shared/MapPanel.cs @@ -47,25 +47,27 @@ namespace MapControl DependencyPropertyHelper.RegisterAttached("AutoCollapse"); public static readonly DependencyProperty LocationProperty = - DependencyPropertyHelper.RegisterAttached("Location", null, false, + DependencyPropertyHelper.RegisterAttached("Location", null, (element, oldValue, newValue) => (element.Parent as MapPanel)?.InvalidateArrange()); public static readonly DependencyProperty BoundingBoxProperty = - DependencyPropertyHelper.RegisterAttached("BoundingBox", null, false, + DependencyPropertyHelper.RegisterAttached("BoundingBox", null, (element, oldValue, newValue) => (element.Parent as MapPanel)?.InvalidateArrange()); private static readonly DependencyProperty ViewPositionProperty = DependencyPropertyHelper.RegisterAttached("ViewPosition"); private static readonly DependencyProperty ParentMapProperty = - DependencyPropertyHelper.RegisterAttached("ParentMap", null, true, - (element, oldValue, newValue) => - { - if (element is IMapElement mapElement) - { - mapElement.ParentMap = newValue; - } - }); + DependencyPropertyHelper.RegisterAttached("ParentMap", null, + (element, oldValue, newValue) => SetParentMap(element, newValue), true); + + private static void SetParentMap(FrameworkElement element, MapBase parentMap) + { + if (element is IMapElement mapElement) + { + mapElement.ParentMap = parentMap; + } + } private MapBase parentMap; diff --git a/MapControl/WPF/DependencyPropertyHelper.WPF.cs b/MapControl/WPF/DependencyPropertyHelper.WPF.cs index fbd67d96..79b30385 100644 --- a/MapControl/WPF/DependencyPropertyHelper.WPF.cs +++ b/MapControl/WPF/DependencyPropertyHelper.WPF.cs @@ -48,8 +48,8 @@ namespace MapControl public static DependencyProperty RegisterAttached( string name, TValue defaultValue = default, - bool inherits = false, - Action changed = null) + Action changed = null, + bool inherits = false) where TOwner : DependencyObject { var metadata = new FrameworkPropertyMetadata diff --git a/MapControl/WinUI/DependencyPropertyHelper.WinUI.cs b/MapControl/WinUI/DependencyPropertyHelper.WinUI.cs index bcdf2869..00c29088 100644 --- a/MapControl/WinUI/DependencyPropertyHelper.WinUI.cs +++ b/MapControl/WinUI/DependencyPropertyHelper.WinUI.cs @@ -31,8 +31,8 @@ namespace MapControl public static DependencyProperty RegisterAttached( string name, TValue defaultValue = default, - bool inherits = false, // unused in WinUI/UWP - Action changed = null) + Action changed = null, + bool inherits = false) // unused in WinUI/UWP where TOwner : DependencyObject { var metadata = changed != null diff --git a/MapUiTools/Shared/MapLayersMenuButton.cs b/MapUiTools/Shared/MapLayersMenuButton.cs index 68aa9f4a..ea457e32 100644 --- a/MapUiTools/Shared/MapLayersMenuButton.cs +++ b/MapUiTools/Shared/MapLayersMenuButton.cs @@ -50,7 +50,7 @@ namespace MapControl.UiTools } public static readonly DependencyProperty MapProperty = - DependencyPropertyHelper.Register(nameof(Map), null, false, + DependencyPropertyHelper.Register(nameof(Map), null, (button, oldValue, newValue) => button.InitializeMenu()); public MapBase Map diff --git a/MapUiTools/Shared/MapProjectionsMenuButton.cs b/MapUiTools/Shared/MapProjectionsMenuButton.cs index a5cab8d0..da193113 100644 --- a/MapUiTools/Shared/MapProjectionsMenuButton.cs +++ b/MapUiTools/Shared/MapProjectionsMenuButton.cs @@ -45,7 +45,7 @@ namespace MapControl.UiTools } public static readonly DependencyProperty MapProperty = - DependencyPropertyHelper.Register(nameof(Map), null, false, + DependencyPropertyHelper.Register(nameof(Map), null, (button, oldValue, newValue) => button.InitializeMenu()); public MapBase Map