在silverlight中从代码后面定义路径数据 [英] Define the path data from code behind in silverlight

查看:96
本文介绍了在silverlight中从代码后面定义路径数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下路径数据在xaml。我想从后面的代码定义相同的路径数据。

 < Path Data =M 250,40 L200,20 L200,60Z/> 


解决方案

来自Codebehind:

 路径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;



编辑



//我们应该设置为true以绘制从lineSegment2到开始点的线

  pathFigure.IsClosed =真正; 


I have the following below path data which is in xaml. I want to define the same path data from the code behind.

<Path  Data="M 250,40 L200,20 L200,60 Z" />

解决方案

From 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;

Edit :

//we should have to set this true to draw the line from lineSegment2 to the start point

pathFigure.IsClosed = true;

这篇关于在silverlight中从代码后面定义路径数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆