gpt4 book ai didi

c# - 使用 RenderedGeometry 作为路径数据不起作用

转载 作者:行者123 更新时间:2023-11-30 15:58:15 26 4
gpt4 key购买 nike

我想绘制一个简单的 Path,它使用 PolygonRenderedGeometry 作为 Data

Polygon polygon = new Polygon();
polygon.Points = new PointCollection { new Point(0, 0), new Point(0, 100), new Point(150, 150) };
var path = new Path
{
Data = polygon.RenderedGeometry,
Stroke = Brushes.LightBlue,
StrokeThickness = 2,
Fill = Brushes.Green,
Opacity = 0.5
};
Panel.SetZIndex(path, 2);
canvas.Children.Add(path);

但是我的 Canvas 没有显示任何内容。

最佳答案

您应该在将几何体渲染到 Canvas 之前强制渲染它。您可以通过调用 PolygonArrangeMeasure 方法来执行此操作:

Polygon polygon = new Polygon();
polygon.Points = new PointCollection { new Point(0, 0), new Point(0, 100), new Point(150, 150) };
polygon.Arrange(new Rect(canvas.RenderSize));
polygon.Measure(canvas.RenderSize);
var path = new Path
{
Data = polygon.RenderedGeometry,
Stroke = Brushes.LightBlue,
StrokeThickness = 2,
Fill = Brushes.Green,
Opacity = 0.5
};
Panel.SetZIndex(path, 2);
canvas.Children.Add(path);

关于c# - 使用 RenderedGeometry 作为路径数据不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43606765/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com