diff --git a/src/Avalonia.Controls/Primitives/OverlayLayer.cs b/src/Avalonia.Controls/Primitives/OverlayLayer.cs
index 2294c70e9b..231743bd0c 100644
--- a/src/Avalonia.Controls/Primitives/OverlayLayer.cs
+++ b/src/Avalonia.Controls/Primitives/OverlayLayer.cs
@@ -3,102 +3,9 @@ using Avalonia.VisualTree;
namespace Avalonia.Controls.Primitives
{
- public class OverlayLayer : Control
+ public class OverlayLayer : Canvas
{
- ///
- /// Defines the Left attached property.
- ///
- public static readonly AttachedProperty LeftProperty =
- AvaloniaProperty.RegisterAttached("Left", 0);
-
- ///
- /// Defines the Top attached property.
- ///
- public static readonly AttachedProperty TopProperty =
- AvaloniaProperty.RegisterAttached("Top", 0);
-
- ///
- /// Defines the InfiniteAvailableSize attached property.
- ///
- public static readonly AttachedProperty InfiniteAvailableSizeProperty =
- AvaloniaProperty.RegisterAttached("InfiniteAvailableSize", false);
-
-
- static OverlayLayer()
- {
- foreach (var p in new []{LeftProperty, TopProperty})
- {
- p.Changed.AddClassHandler((target, e) =>
- {
- if (target.GetVisualParent() is OverlayLayer layer)
- layer.InvalidateArrange();
- });
- }
- }
-
public Size AvailableSize { get; private set; }
-
- ///
- /// Gets the value of the Left attached property for a control.
- ///
- /// The control.
- /// The control's left coordinate.
- public static double GetLeft(AvaloniaObject element)
- {
- return element.GetValue(LeftProperty);
- }
-
- ///
- /// Sets the value of the Left attached property for a control.
- ///
- /// The control.
- /// The left value.
- public static void SetLeft(AvaloniaObject element, double value)
- {
- element.SetValue(LeftProperty, value);
- }
-
- ///
- /// Gets the value of the Top attached property for a control.
- ///
- /// The control.
- /// The control's top coordinate.
- public static double GetTop(AvaloniaObject element)
- {
- return element.GetValue(TopProperty);
- }
-
- ///
- /// Sets the value of the Top attached property for a control.
- ///
- /// The control.
- /// The top value.
- public static void SetTop(AvaloniaObject element, double value)
- {
- element.SetValue(TopProperty, value);
- }
-
- ///
- /// Gets the value of the Top attached property for a control.
- ///
- /// The control.
- /// The control's top coordinate.
- public static bool GetInfiniteAvailableSize(AvaloniaObject element)
- {
- return element.GetValue(InfiniteAvailableSizeProperty);
- }
-
- ///
- /// Sets the value of the Top attached property for a control.
- ///
- /// The control.
- /// The top value.
- public static void SetInfiniteAvailableSize(AvaloniaObject element, bool value)
- {
- element.SetValue(InfiniteAvailableSizeProperty, value);
- }
-
-
public static OverlayLayer GetOverlayLayer(IVisual visual)
{
foreach(var v in visual.GetVisualAncestors())
@@ -113,34 +20,13 @@ namespace Avalonia.Controls.Primitives
return null;
}
-
- public void Add(Control v)
- {
- VisualChildren.Add(v);
- InvalidateMeasure();
- InvalidateArrange();
- }
-
- public void Remove(Control v) => VisualChildren.Remove(v);
- protected override Size MeasureOverride(Size availableSize)
- {
-
- var infinite = new Size(double.PositiveInfinity, double.PositiveInfinity);
- foreach (Control v in VisualChildren)
- v.Measure(GetInfiniteAvailableSize(v) ? infinite : availableSize);
-
- return new Size();
- }
-
protected override Size ArrangeOverride(Size finalSize)
{
// We are saving it here since child controls might need to know the entire size of the overlay
// and Bounds won't be updated in time
AvailableSize = finalSize;
- foreach (Control v in VisualChildren)
- v.Arrange(new Rect(GetLeft(v), GetTop(v), v.DesiredSize.Width, v.DesiredSize.Height));
- return finalSize;
+ return base.ArrangeOverride(finalSize);
}
}
}
diff --git a/src/Avalonia.Controls/Primitives/PopupHost.cs b/src/Avalonia.Controls/Primitives/PopupHost.cs
index 3d6809c061..a9dcb56ecb 100644
--- a/src/Avalonia.Controls/Primitives/PopupHost.cs
+++ b/src/Avalonia.Controls/Primitives/PopupHost.cs
@@ -12,7 +12,7 @@ using Avalonia.VisualTree;
namespace Avalonia.Controls.Primitives
{
- public class PopupHost : Control, IPopupHost, IInteractive, IManagedPopupPositionerPopup
+ public class PopupHost : Decorator, IPopupHost, IInteractive, IManagedPopupPositionerPopup
{
private readonly OverlayLayer _overlayLayer;
private PopupPositionerParameters _positionerParameters = new PopupPositionerParameters();
@@ -28,13 +28,7 @@ namespace Avalonia.Controls.Primitives
public void SetContent(IControl control)
{
- if (_content == control)
- return;
- if (_content != null)
- VisualChildren.Remove(_content);
- _content = control;
- if (_content != null)
- VisualChildren.Add(_content);
+ Child = control;
}
public IVisual VisualRoot => null;
@@ -47,13 +41,13 @@ namespace Avalonia.Controls.Primitives
public void Show()
{
- _overlayLayer.Add(this);
+ _overlayLayer.Children.Add(this);
_shown = true;
}
public void Hide()
{
- _overlayLayer.Remove(this);
+ _overlayLayer.Children.Remove(this);
_shown = false;
}