MapPanel constructor

This commit is contained in:
ClemensFischer 2025-06-10 23:50:58 +02:00
parent fde4eccf12
commit 71e7e29200
4 changed files with 22 additions and 30 deletions

View file

@ -18,14 +18,6 @@
AffectsParentArrange<MapPanel>(LocationProperty, BoundingBoxProperty); AffectsParentArrange<MapPanel>(LocationProperty, BoundingBoxProperty);
} }
public MapPanel()
{
if (this is MapBase)
{
SetValue(ParentMapProperty, this);
}
}
public static MapBase GetParentMap(Control element) public static MapBase GetParentMap(Control element)
{ {
return (MapBase)element.GetValue(ParentMapProperty); return (MapBase)element.GetValue(ParentMapProperty);

View file

@ -44,6 +44,22 @@ namespace MapControl
}, },
true); // inherits true); // inherits
public MapPanel()
{
UseLayoutRounding = false;
if (this is MapBase)
{
SetValue(ParentMapProperty, this);
}
else
{
InitMapPanel();
}
}
partial void InitMapPanel();
private MapBase parentMap; private MapBase parentMap;
/// <summary> /// <summary>

View file

@ -20,14 +20,6 @@ namespace MapControl
protected IEnumerable<FrameworkElement> ChildElements => InternalChildren.OfType<FrameworkElement>(); protected IEnumerable<FrameworkElement> ChildElements => InternalChildren.OfType<FrameworkElement>();
public MapPanel()
{
if (this is MapBase)
{
SetValue(ParentMapProperty, this);
}
}
public static MapBase GetParentMap(FrameworkElement element) public static MapBase GetParentMap(FrameworkElement element)
{ {
return (MapBase)element.GetValue(ParentMapProperty); return (MapBase)element.GetValue(ParentMapProperty);

View file

@ -25,26 +25,18 @@ namespace MapControl
protected IEnumerable<FrameworkElement> ChildElements => Children.OfType<FrameworkElement>(); protected IEnumerable<FrameworkElement> ChildElements => Children.OfType<FrameworkElement>();
public MapPanel() partial void InitMapPanel()
{ {
UseLayoutRounding = false;
InitMapElement(this); InitMapElement(this);
} }
public static void InitMapElement(FrameworkElement element) public static void InitMapElement(FrameworkElement element)
{ {
if (element is MapBase) // Workaround for missing property value inheritance.
{ // Loaded and Unloaded handlers set and clear the ParentMap property value.
element.SetValue(ParentMapProperty, element); //
} element.Loaded += (s, e) => GetParentMap((FrameworkElement)s);
else 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) public static MapBase GetParentMap(FrameworkElement element)