我目前正在尝试为我的 WPF 添加一个 BezierSegment
到我的 Canvas 。我遇到了不正确转换的编译时错误:
Argument 1: cannot convert from 'System.Windows.Media.PathGeometry' to 'System.Windows.UIElement'
这就是我目前所拥有的...
//bezier curve it
BezierSegment curve = new BezierSegment(startPoint, endPoint,controlPoint,false);
// Set up the Path to insert the segments
PathGeometry path = new PathGeometry();
PathFigure pathFigure = new PathFigure();
pathFigure.StartPoint = hs.LeStartingPoint;
pathFigure.IsClosed = true;
path.Figures.Add(pathFigure);
pathFigure.Segments.Add(curve);
System.Windows.Shapes.Path p = new Path();
p.Data = path;
this.mainWindow.MyCanvas.Children.Add(path);
任何帮助将不胜感激!
最佳答案
您必须将 p
(Path
) 添加到 Canvas
,而不是 path
(PathGeometry
)。
BezierSegment curve = new BezierSegment(new Point(11,11), new Point(22,22), new Point(15,15), false);
// Set up the Path to insert the segments
PathGeometry path = new PathGeometry();
PathFigure pathFigure = new PathFigure();
pathFigure.StartPoint = new Point(11, 11);
pathFigure.IsClosed = true;
path.Figures.Add(pathFigure);
pathFigure.Segments.Add(curve);
System.Windows.Shapes.Path p = new Path();
p.Stroke = Brushes.Red;
p.Data = path;
MyCanvas.Children.Add(p); // Here
关于c# - 添加(BezierSegment 到 a) Canvas 路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17766425/