using System; using Avalonia; using Avalonia.Controls; using Avalonia.Layout; namespace SukiUI.Controls { public class ContentExpandControl : ContentControl { public static readonly StyledProperty MultiplierProperty = AvaloniaProperty.Register(nameof(Multiplier)); public double Multiplier { get => GetValue(MultiplierProperty); set => SetValue(MultiplierProperty, value); } public static readonly StyledProperty OrientationProperty = AvaloniaProperty.Register(nameof(Orientation)); public Orientation Orientation { get => GetValue(OrientationProperty); set => SetValue(OrientationProperty, value); } static ContentExpandControl() { AffectsArrange(MultiplierProperty, OrientationProperty); AffectsMeasure(MultiplierProperty, OrientationProperty); } protected override Size MeasureCore(Size availableSize) { var result = base.MeasureCore(availableSize); return result; } protected override Size ArrangeOverride(Size finalSize) { var result = base.ArrangeOverride(finalSize); // A very gross way to actually get the bloody thing to draw... if (Parent is Control c) c.Margin = new Thickness(1); return result; } protected override Size MeasureOverride(Size availableSize) { var result = base.MeasureOverride(availableSize); var w = result.Width; var h = result.Height; switch (Orientation) { case Orientation.Horizontal: w *= Multiplier; break; case Orientation.Vertical: h *= Multiplier; break; default: throw new ArgumentOutOfRangeException(); } // A very gross way to actually get the bloody thing to draw... if (Parent is Control c) c.Margin = new Thickness(0); return new Size(w, h); } } }