Mal*_*olm 7 silverlight-4.0 c#-4.0
我在xaml中有以下路径数据.我想从后面的代码中定义相同的路径数据.
<Path Data="M 250,40 L200,20 L200,60 Z" />
Run Code Online (Sandbox Code Playgroud)
Mal*_*olm 16
来自Codebehind:
Path orangePath = new Path();
PathFigure pathFigure = new PathFigure();
pathFigure.StartPoint = new Point(250, 40);
LineSegment lineSegment1 = new LineSegment();
lineSegment1.Point = new Point(200, 20);
pathFigure.Segments.Add(lineSegment1);
LineSegment lineSegment2 = new LineSegment();
lineSegment2.Point = new Point(200, 60);
pathFigure.Segments.Add(lineSegment2);
PathGeometry pathGeometry = new PathGeometry();
pathGeometry.Figures = new PathFigureCollection();
pathGeometry.Figures.Add(pathFigure);
orangePath.Data = pathGeometry;
Run Code Online (Sandbox Code Playgroud)
编辑:
//我们必须将此设置为true以将lineSegment2中的行绘制到起始点
pathFigure.IsClosed = true;
Run Code Online (Sandbox Code Playgroud)
Tho*_*que 12
你需要使用TypeConverter:
Path path = new Path();
string sData = "M 250,40 L200,20 L200,60 Z";
var converter = TypeDescriptor.GetConverter(typeof(Geometry));
path.Data = (Geometry)converter.ConvertFrom(sData);
Run Code Online (Sandbox Code Playgroud)