我需要在同一张图中用不同颜色、粗细等线条绘制。
我可以创建两个 PathGeometry 实例,但不能在它们上设置颜色。
我可以创建两个 Path 实例,但无法将它们显示在我的控件中。
我究竟做错了什么?
感谢您的任何评论!
安德斯,丹麦。
下面的代码仅在我的控件中显示“集合”,但我认为它可能是答案的起点......
var pathFigure1 = new PathFigure(new Point(0, 0),
new List<PathSegment> {new LineSegment(new Point(10, 10), true)}, false);
var pathFigure2 = new PathFigure(new Point(20, 20),
new List<PathSegment> {new LineSegment(new Point(30, 30), true)}, false);
var g1 = new PathGeometry(new List<PathFigure> {pathFigure1});
var g2 = new PathGeometry(new List<PathFigure> {pathFigure2});
var p1 = new System.Windows.Shapes.Path
{
Data = g1,
Stroke = new SolidColorBrush(Color.FromRgb(0, 0, 0))
};
var p2 = new System.Windows.Shapes.Path
{
Data = g2,
Stroke = new SolidColorBrush(Color.FromRgb(170, 87, 170))
};
var content = new Canvas();
content.Children.Add(p1);
content.Children.Add(p2);
Content = content;