DependencyPropertyHelper

This commit is contained in:
ClemensFischer 2024-05-23 19:21:28 +02:00
parent bc12b388de
commit b7afd27c91
7 changed files with 21 additions and 19 deletions

View file

@ -19,7 +19,7 @@ namespace MapControl.MBTiles
public class MBTileLayer : MapTileLayer public class MBTileLayer : MapTileLayer
{ {
public static readonly DependencyProperty FileProperty = public static readonly DependencyProperty FileProperty =
DependencyPropertyHelper.Register<MBTileLayer, string>(nameof(File), null, false, DependencyPropertyHelper.Register<MBTileLayer, string>(nameof(File), null,
async (layer, oldValue, newValue) => await layer.FilePropertyChanged(newValue)); async (layer, oldValue, newValue) => await layer.FilePropertyChanged(newValue));
public string File public string File

View file

@ -31,8 +31,8 @@ namespace MapControl
public static AttachedProperty<TValue> RegisterAttached<TOwner, TValue>( public static AttachedProperty<TValue> RegisterAttached<TOwner, TValue>(
string name, string name,
TValue defaultValue = default, TValue defaultValue = default,
bool inherits = false, Action<Control, TValue, TValue> changed = null,
Action<Control, TValue, TValue> changed = null) bool inherits = false)
where TOwner : AvaloniaObject where TOwner : AvaloniaObject
{ {
var property = AvaloniaProperty.RegisterAttached<TOwner, Control, TValue>(name, defaultValue, inherits); var property = AvaloniaProperty.RegisterAttached<TOwner, Control, TValue>(name, defaultValue, inherits);

View file

@ -47,25 +47,27 @@ namespace MapControl
DependencyPropertyHelper.RegisterAttached<MapPanel, bool>("AutoCollapse"); DependencyPropertyHelper.RegisterAttached<MapPanel, bool>("AutoCollapse");
public static readonly DependencyProperty LocationProperty = public static readonly DependencyProperty LocationProperty =
DependencyPropertyHelper.RegisterAttached<MapPanel, Location>("Location", null, false, DependencyPropertyHelper.RegisterAttached<MapPanel, Location>("Location", null,
(element, oldValue, newValue) => (element.Parent as MapPanel)?.InvalidateArrange()); (element, oldValue, newValue) => (element.Parent as MapPanel)?.InvalidateArrange());
public static readonly DependencyProperty BoundingBoxProperty = public static readonly DependencyProperty BoundingBoxProperty =
DependencyPropertyHelper.RegisterAttached<MapPanel, BoundingBox>("BoundingBox", null, false, DependencyPropertyHelper.RegisterAttached<MapPanel, BoundingBox>("BoundingBox", null,
(element, oldValue, newValue) => (element.Parent as MapPanel)?.InvalidateArrange()); (element, oldValue, newValue) => (element.Parent as MapPanel)?.InvalidateArrange());
private static readonly DependencyProperty ViewPositionProperty = private static readonly DependencyProperty ViewPositionProperty =
DependencyPropertyHelper.RegisterAttached<MapPanel, Point?>("ViewPosition"); DependencyPropertyHelper.RegisterAttached<MapPanel, Point?>("ViewPosition");
private static readonly DependencyProperty ParentMapProperty = private static readonly DependencyProperty ParentMapProperty =
DependencyPropertyHelper.RegisterAttached<MapPanel, MapBase>("ParentMap", null, true, DependencyPropertyHelper.RegisterAttached<MapPanel, MapBase>("ParentMap", null,
(element, oldValue, newValue) => (element, oldValue, newValue) => SetParentMap(element, newValue), true);
{
if (element is IMapElement mapElement) private static void SetParentMap(FrameworkElement element, MapBase parentMap)
{ {
mapElement.ParentMap = newValue; if (element is IMapElement mapElement)
} {
}); mapElement.ParentMap = parentMap;
}
}
private MapBase parentMap; private MapBase parentMap;

View file

@ -48,8 +48,8 @@ namespace MapControl
public static DependencyProperty RegisterAttached<TOwner, TValue>( public static DependencyProperty RegisterAttached<TOwner, TValue>(
string name, string name,
TValue defaultValue = default, TValue defaultValue = default,
bool inherits = false, Action<FrameworkElement, TValue, TValue> changed = null,
Action<FrameworkElement, TValue, TValue> changed = null) bool inherits = false)
where TOwner : DependencyObject where TOwner : DependencyObject
{ {
var metadata = new FrameworkPropertyMetadata var metadata = new FrameworkPropertyMetadata

View file

@ -31,8 +31,8 @@ namespace MapControl
public static DependencyProperty RegisterAttached<TOwner, TValue>( public static DependencyProperty RegisterAttached<TOwner, TValue>(
string name, string name,
TValue defaultValue = default, TValue defaultValue = default,
bool inherits = false, // unused in WinUI/UWP Action<FrameworkElement, TValue, TValue> changed = null,
Action<FrameworkElement, TValue, TValue> changed = null) bool inherits = false) // unused in WinUI/UWP
where TOwner : DependencyObject where TOwner : DependencyObject
{ {
var metadata = changed != null var metadata = changed != null

View file

@ -50,7 +50,7 @@ namespace MapControl.UiTools
} }
public static readonly DependencyProperty MapProperty = public static readonly DependencyProperty MapProperty =
DependencyPropertyHelper.Register<MapLayersMenuButton, MapBase>(nameof(Map), null, false, DependencyPropertyHelper.Register<MapLayersMenuButton, MapBase>(nameof(Map), null,
(button, oldValue, newValue) => button.InitializeMenu()); (button, oldValue, newValue) => button.InitializeMenu());
public MapBase Map public MapBase Map

View file

@ -45,7 +45,7 @@ namespace MapControl.UiTools
} }
public static readonly DependencyProperty MapProperty = public static readonly DependencyProperty MapProperty =
DependencyPropertyHelper.Register<MapProjectionsMenuButton, MapBase>(nameof(Map), null, false, DependencyPropertyHelper.Register<MapProjectionsMenuButton, MapBase>(nameof(Map), null,
(button, oldValue, newValue) => button.InitializeMenu()); (button, oldValue, newValue) => button.InitializeMenu());
public MapBase Map public MapBase Map