|
|
@@ -8,7 +8,7 @@ namespace Avalonia.Controls
|
|
|
/// </summary>
|
|
|
public class Viewbox : Control
|
|
|
{
|
|
|
- private Decorator _containerVisual;
|
|
|
+ private ViewboxContainer _containerVisual;
|
|
|
|
|
|
/// <summary>
|
|
|
/// Defines the <see cref="Stretch"/> property.
|
|
|
@@ -37,9 +37,8 @@ namespace Avalonia.Controls
|
|
|
|
|
|
public Viewbox()
|
|
|
{
|
|
|
- _containerVisual = new Decorator();
|
|
|
+ _containerVisual = new ViewboxContainer();
|
|
|
_containerVisual.RenderTransformOrigin = RelativePoint.TopLeft;
|
|
|
- LogicalChildren.Add(_containerVisual);
|
|
|
VisualChildren.Add(_containerVisual);
|
|
|
}
|
|
|
|
|
|
@@ -88,7 +87,22 @@ namespace Avalonia.Controls
|
|
|
|
|
|
if (change.Property == ChildProperty)
|
|
|
{
|
|
|
+ var (oldChild, newChild) = change.GetOldAndNewValue<IControl>();
|
|
|
+
|
|
|
+ if (oldChild is not null)
|
|
|
+ {
|
|
|
+ ((ISetLogicalParent)oldChild).SetParent(null);
|
|
|
+ LogicalChildren.Remove(oldChild);
|
|
|
+ }
|
|
|
+
|
|
|
_containerVisual.Child = change.GetNewValue<IControl>();
|
|
|
+
|
|
|
+ if (newChild is not null)
|
|
|
+ {
|
|
|
+ ((ISetLogicalParent)newChild).SetParent(this);
|
|
|
+ LogicalChildren.Add(newChild);
|
|
|
+ }
|
|
|
+
|
|
|
InvalidateMeasure();
|
|
|
}
|
|
|
}
|
|
|
@@ -129,5 +143,28 @@ namespace Avalonia.Controls
|
|
|
|
|
|
return finalSize;
|
|
|
}
|
|
|
+
|
|
|
+ private class ViewboxContainer : Control
|
|
|
+ {
|
|
|
+ private IControl? _child;
|
|
|
+
|
|
|
+ public IControl? Child
|
|
|
+ {
|
|
|
+ get => _child;
|
|
|
+ set
|
|
|
+ {
|
|
|
+ if (_child != value)
|
|
|
+ {
|
|
|
+ if (_child is not null)
|
|
|
+ VisualChildren.Remove(_child);
|
|
|
+
|
|
|
+ _child = value;
|
|
|
+
|
|
|
+ if (_child is not null)
|
|
|
+ VisualChildren.Add(_child);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|