Files
ShrlAlgoToolkit/NeuWPF/NeoUI/Controls/Decorations/ClippingBorder.cs
ShrlAlgo 955a01f564 整理
2025-08-20 12:10:35 +08:00

40 lines
1.5 KiB
C#

namespace NeoUI.Controls.Decorations;
/// <summary>
/// 可裁剪 Boder
/// </summary>
public class ClippingBorder : System.Windows.Controls.Border
{
/// <inheritdoc/>
protected override void OnRender(DrawingContext dc)
{
if(Child is { })
{
var topLeft = CornerRadius.TopLeft - Math.Max(BorderThickness.Top, BorderThickness.Left) / 2;
var bottomLeft = CornerRadius.BottomLeft - Math.Max(BorderThickness.Bottom, BorderThickness.Left) / 2;
var topRight = CornerRadius.TopRight - Math.Max(BorderThickness.Top, BorderThickness.Right) / 2;
var bottomRight = CornerRadius.BottomRight - Math.Max(BorderThickness.Bottom, BorderThickness.Right) / 2;
if(topLeft < 0)
topLeft = 0;
if(bottomLeft < 0)
bottomLeft = 0;
if(topRight < 0)
topRight = 0;
if(bottomRight < 0)
bottomRight = 0;
var mask = new System.Windows.Controls.Border()
{
CornerRadius = new CornerRadius(topLeft, topRight, bottomRight, bottomLeft),
Height = ActualHeight - BorderThickness.Top - BorderThickness.Bottom,
Width = ActualWidth - BorderThickness.Left - BorderThickness.Right,
Background = Brushes.Black,
SnapsToDevicePixels = true,
};
Child.OpacityMask = new VisualBrush(mask);
}
base.OnRender(dc);
}
}