是否可以更改 WPF 元素的边界?
Is it possible to alter the bounds of a WPF element?
我正在动态创建 Path
,我注意到形状的边界 Rect
远大于路径本身,如下图所示。
是否可以更改这些边界? 不幸的是 PathGeometry.Bounds
属性 是只读的。
ps:如果有用ps,我有兴趣缩小边界,这样我就可以将路径的 RenderTransformOrigin
设置为 new Point(0.5,0.5)
以旋转(RotateTransform
) 围绕自身的路径。
创建 PathFigure
我定义了 4 个点,然后我创建了三个 LineSegment
和 ArcSegment
。我创建了一个 Circle
结构作为计算这些点的指南。
private PathFigure CreateFigure()
{
var lineAB = new LineSegment(pointB, true);
var arcBC = new ArcSegment(pointC, new Size(_outerCircle.Radius, _outerCircle.Radius), 0, false, SweepDirection.Clockwise, true);
var lineCD = new LineSegment(pointD, true);
return new PathFigure(pointA, new List<PathSegment> { lineAB, arcBC, lineCD }, true);
}
由于边界在定义后无法更改,因此将 Path
作为子项添加到 Grid
或 Border
并设置 Path.Stretch="Fill"
会在布局过程中强制边界由路径填充。
我正在动态创建 Path
,我注意到形状的边界 Rect
远大于路径本身,如下图所示。
是否可以更改这些边界? 不幸的是 PathGeometry.Bounds
属性 是只读的。
ps:如果有用ps,我有兴趣缩小边界,这样我就可以将路径的 RenderTransformOrigin
设置为 new Point(0.5,0.5)
以旋转(RotateTransform
) 围绕自身的路径。
创建 PathFigure
我定义了 4 个点,然后我创建了三个 LineSegment
和 ArcSegment
。我创建了一个 Circle
结构作为计算这些点的指南。
private PathFigure CreateFigure()
{
var lineAB = new LineSegment(pointB, true);
var arcBC = new ArcSegment(pointC, new Size(_outerCircle.Radius, _outerCircle.Radius), 0, false, SweepDirection.Clockwise, true);
var lineCD = new LineSegment(pointD, true);
return new PathFigure(pointA, new List<PathSegment> { lineAB, arcBC, lineCD }, true);
}
由于边界在定义后无法更改,因此将 Path
作为子项添加到 Grid
或 Border
并设置 Path.Stretch="Fill"
会在布局过程中强制边界由路径填充。