c# - 添加(BezierSegment 到 a) Canvas 路径

标签 c# wpf drawing bezier

我目前正在尝试为我的 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/

相关文章:

c# - 无法停止打印

c# - 使用关联打开文件

c# - 单击 gridview 列标题整个 gridview 试图覆盖窗口

c# - DataGrid 显示错误的日期格式

c# - 使用模型自动属性时如何将数据从模型传递到 View 模型?

c# - 如何在 C# 控制台应用程序中绘制框、矩形

javascript - 响应式 Canvas 上下文

c# - 如何按顺序检查字符串中的单词

c# - 获取错误 "Operator ' + =' is ambiguous on operands of type ' 矢量 3' and ' 矢量 2'"

wpf - WPF 中的自定义线条绘图