我正在进行自定义控件,它Render
看起来像这样
protected override void OnRender(DrawingContext context)
{
var geometry = new PathGeometry(new[] { new PathFigure(new Point(0, 0), new [] {
new LineSegment(new Point(ActualWidth, 0), true),
new LineSegment(new Point(ActualWidth, ActualHeight), true),
new LineSegment(new Point(0, ActualHeight), true),
}, true) });
context.DrawGeometry(new LinearGradientBrush(Colors.White, Colors.Black, 90),
new Pen(Brushes.White, 10), geometry);
}
为什么中风是如此无知?在屏幕截图上,您可以看到白色笔触超出了控制范围
我不能简单地用进行裁剪ClipToBounds
,因为我需要精确地绘制并且希望使用笔触而不是必须手动绘制轮廓(图比矩形要复杂得多)。
我可以根据校正后的尺寸计算几何形状,但我不知道如何计算笔划图。
如何DrawGeometry
在控制范围内使行程合适?也许还有其他方法可以绘制轮廓复杂的图形?
笔总是精确绘制在几何轮廓的中间。因此,对于厚度为10的钢笔,您将不得不创建5像素边距的几何图形:
context.DrawRectangle(
new LinearGradientBrush(Colors.White, Colors.Black, 90),
new Pen(Brushes.White, 10),
new Rect(5, 5, ActualWidth - 10, ActualHeight - 10));
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句