5

BezierSegment現在、WPF のキャンバスにを追加しようとしています。不適切なキャストのコンパイル時エラーが発生します。

引数 1: 'System.Windows.Media.PathGeometry' から '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);

どんな助けでも大歓迎です!

4

2 に答える 2

6

( )ではなくp( Path) をに追加する必要があります。CanvaspathPathGeometry

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
于 2013-07-20T20:55:29.723 に答える