csharpc-sharpdotnetxamlavaloniauicross-platformcross-platform-xamlavaloniaguimulti-platformuser-interfacedotnetcore
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
96 lines
3.1 KiB
96 lines
3.1 KiB
// -----------------------------------------------------------------------
|
|
// <copyright file="Border.cs" company="Steven Kirk">
|
|
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|
// </copyright>
|
|
// -----------------------------------------------------------------------
|
|
|
|
namespace Perspex.Controls
|
|
{
|
|
using System;
|
|
using System.Reactive.Linq;
|
|
using Perspex.Layout;
|
|
using Perspex.Media;
|
|
|
|
public class Border : Decorator
|
|
{
|
|
public static readonly PerspexProperty<Brush> BackgroundProperty =
|
|
PerspexProperty.Register<Border, Brush>("Background");
|
|
|
|
public static readonly PerspexProperty<Brush> BorderBrushProperty =
|
|
PerspexProperty.Register<Border, Brush>("BorderBrush");
|
|
|
|
public static readonly PerspexProperty<double> BorderThicknessProperty =
|
|
PerspexProperty.Register<Border, double>("BorderThickness");
|
|
|
|
static Border()
|
|
{
|
|
Control.AffectsRender(Border.BackgroundProperty);
|
|
Control.AffectsRender(Border.BorderBrushProperty);
|
|
}
|
|
|
|
public Brush Background
|
|
{
|
|
get { return this.GetValue(BackgroundProperty); }
|
|
set { this.SetValue(BackgroundProperty, value); }
|
|
}
|
|
|
|
public Brush BorderBrush
|
|
{
|
|
get { return this.GetValue(BorderBrushProperty); }
|
|
set { this.SetValue(BorderBrushProperty, value); }
|
|
}
|
|
|
|
public double BorderThickness
|
|
{
|
|
get { return this.GetValue(BorderThicknessProperty); }
|
|
set { this.SetValue(BorderThicknessProperty, value); }
|
|
}
|
|
|
|
public override void Render(IDrawingContext context)
|
|
{
|
|
Brush background = this.Background;
|
|
Brush borderBrush = this.BorderBrush;
|
|
double borderThickness = this.BorderThickness;
|
|
Rect rect = new Rect(this.Bounds.Size).Deflate(this.BorderThickness);
|
|
|
|
if (background != null)
|
|
{
|
|
context.FillRectange(background, rect);
|
|
}
|
|
|
|
if (borderBrush != null && borderThickness > 0)
|
|
{
|
|
context.DrawRectange(new Pen(borderBrush, borderThickness), rect);
|
|
}
|
|
}
|
|
|
|
protected override Size ArrangeOverride(Size finalSize)
|
|
{
|
|
Control content = this.Content;
|
|
|
|
if (content != null)
|
|
{
|
|
Thickness padding = this.Padding + new Thickness(this.BorderThickness);
|
|
content.Arrange(new Rect(finalSize).Deflate(padding));
|
|
}
|
|
|
|
return finalSize;
|
|
}
|
|
|
|
protected override Size MeasureOverride(Size availableSize)
|
|
{
|
|
var content = this.Content;
|
|
var padding = this.Padding + new Thickness(this.BorderThickness);
|
|
|
|
if (content != null)
|
|
{
|
|
content.Measure(availableSize.Deflate(padding));
|
|
return content.DesiredSize.Inflate(padding);
|
|
}
|
|
else
|
|
{
|
|
return new Size(padding.Left + padding.Right, padding.Bottom + padding.Top);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|