silverlight - Edit Path Programatically -


is possible edit path programatically?

i'm trying create usercontrol acts horizontal meter width dynamic. have created path in xaml , planned on having int property controls width of meter dynamically. has rounded edges had planned edit x coordinates on right end of meter shrink meter keep same rounded corners. see data property on path don't understand how can edit it.

is there better approach, perhaps?

if you're setting path.data directly, won't able edit in code behind. if want able that, should use pathgeometry instead. msdn

as can see preceding examples, 2 mini-languages similar. it's possible use pathgeometry in situation use streamgeometry; 1 should use? use streamgeometry when don't need modify path after creating it; use pathgeometry if need modify path.

the following 2 path's equivalent, later 1 can modified in code behind

<!-- path 1: using streamgeometry --> <path x:name="mypath"       stroke="black"       strokethickness="10"       margin="20"       data="m 10,10 l 100,10 l 100,200 l 10,200 z"/> <!-- path 2: using pathgeometry--> <path x:name="mypath2"     stroke="black"     strokethickness="10"     margin="20">     <path.data>         <pathgeometry>             <pathgeometry.figures>                 <pathfigure x:name="figure1" startpoint="10, 10" isclosed="true">                     <linesegment x:name="line1" point="100, 10"/>                     <linesegment x:name="line2" point="100, 200"/>                     <linesegment x:name="line3" point="10, 200"/>                 </pathfigure>             </pathgeometry.figures>         </pathgeometry>     </path.data> </path> 

to modify mypath2 in code behind, can access pathfigure , linesegments either name

private void movepathhorizontally() {     figure1.startpoint = new point(figure1.startpoint.x + 10, figure1.startpoint.y);     line1.point = new point(line1.point.x + 10, line1.point.y);     line2.point = new point(line2.point.x + 10, line2.point.y);     line3.point = new point(line3.point.x + 10, line3.point.y); } 

or this

private void movepathhorizontally() {     pathgeometry pathgeometry = mypath2.data pathgeometry;     pathfigurecollection pathfigures = pathgeometry.figures;     foreach (pathfigure pathfigure in pathfigures)     {         pathfigure.startpoint = new point(pathfigure.startpoint.x + 10, pathfigure.startpoint.y);          pathsegmentcollection pathsegments = pathfigure.segments;         foreach (pathsegment pathsegment in pathsegments)         {             if (pathsegment linesegment)             {                 linesegment linesegment = pathsegment linesegment;                 linesegment.point = new point(linesegment.point.x + 10, linesegment.point.y);             }         }     } } 

Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -