using Avalonia.Controls.Utils; using Avalonia.Layout; using Avalonia.Media; namespace Avalonia.Controls { /// /// A control which decorates a child with a border and background. /// public partial class Border : Decorator { /// /// Defines the property. /// public static readonly StyledProperty BackgroundProperty = AvaloniaProperty.Register(nameof(Background)); /// /// Defines the property. /// public static readonly StyledProperty BorderBrushProperty = AvaloniaProperty.Register(nameof(BorderBrush)); /// /// Defines the property. /// public static readonly StyledProperty BorderThicknessProperty = AvaloniaProperty.Register(nameof(BorderThickness)); /// /// Defines the property. /// public static readonly StyledProperty CornerRadiusProperty = AvaloniaProperty.Register(nameof(CornerRadius)); /// /// Defines the property. /// public static readonly StyledProperty BoxShadowProperty = AvaloniaProperty.Register(nameof(BoxShadow)); private readonly BorderRenderHelper _borderRenderHelper = new BorderRenderHelper(); /// /// Initializes static members of the class. /// static Border() { AffectsRender( BackgroundProperty, BorderBrushProperty, BorderThicknessProperty, CornerRadiusProperty, BoxShadowProperty); AffectsMeasure(BorderThicknessProperty); } /// /// Gets or sets a brush with which to paint the background. /// public IBrush Background { get { return GetValue(BackgroundProperty); } set { SetValue(BackgroundProperty, value); } } /// /// Gets or sets a brush with which to paint the border. /// public IBrush BorderBrush { get { return GetValue(BorderBrushProperty); } set { SetValue(BorderBrushProperty, value); } } /// /// Gets or sets the thickness of the border. /// public Thickness BorderThickness { get { return GetValue(BorderThicknessProperty); } set { SetValue(BorderThicknessProperty, value); } } /// /// Gets or sets the radius of the border rounded corners. /// public CornerRadius CornerRadius { get { return GetValue(CornerRadiusProperty); } set { SetValue(CornerRadiusProperty, value); } } /// /// Gets or sets the box shadow effect parameters /// public BoxShadows BoxShadow { get => GetValue(BoxShadowProperty); set => SetValue(BoxShadowProperty, value); } /// /// Renders the control. /// /// The drawing context. public override void Render(DrawingContext context) { _borderRenderHelper.Render(context, Bounds.Size, BorderThickness, CornerRadius, Background, BorderBrush, BoxShadow); } /// /// Measures the control. /// /// The available size. /// The desired size of the control. protected override Size MeasureOverride(Size availableSize) { return LayoutHelper.MeasureChild(Child, availableSize, Padding, BorderThickness); } /// /// Arranges the control's child. /// /// The size allocated to the control. /// The space taken. protected override Size ArrangeOverride(Size finalSize) { return LayoutHelper.ArrangeChild(Child, finalSize, Padding, BorderThickness); } } }