Reputation: 245
I'm using paths to create a specific shape. What is the best way to group all the paths so I'll be able to use them later in another location without re-positioning the paths?
Any suggestions will be great, thank you!
Upvotes: 2
Views: 4569
Reputation: 518
You can group then in a canvas and then just re-position your canvas. Naming every path point would give you the ability to modify the shape.... You can create a new class called MyOwnShape that inherits the Canvas class, and then attach an event for every point of the canvas to drag and drop so the shape gets modified. You might also put your content inside a grill but you wont be able to position your shapes with that kind of precision. If i understood corectly what you want to achive.Your class should looke like this
class MyOwnShapes : Canvas {
List<Path> myListOfPaths;
public void AddPath(Path myPath){
this.Children.Add(path);
myListOfPaths.Add(path); // this is used for your internal computation so it wont affect the effective drawin components.
}
}
I hope this example is good for you.
http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh465055.aspx http://www.windowsphonegeek.com/tips/drawing-in-wp7-3-understanding-path-shapes
Upvotes: 2
Reputation: 128136
If the question is about a complex shape with just one fill and stroke, an option would be to use just one Path instance with a PathGeometry with multiple Figures. See the following example from MSDN:
<Path Stroke="Black" StrokeThickness="1">
<Path.Data>
<PathGeometry>
<PathGeometry.Figures>
<PathFigureCollection>
<PathFigure IsClosed="True" StartPoint="10,100">
<PathFigure.Segments>
<PathSegmentCollection>
<LineSegment Point="100,100" />
<LineSegment Point="100,50" />
</PathSegmentCollection>
</PathFigure.Segments>
</PathFigure>
<PathFigure IsClosed="True" StartPoint="10,10">
<PathFigure.Segments>
<PathSegmentCollection>
<LineSegment Point="100,10" />
<LineSegment Point="100,40" />
</PathSegmentCollection>
</PathFigure.Segments>
</PathFigure>
</PathFigureCollection>
</PathGeometry.Figures>
</PathGeometry>
</Path.Data>
</Path>
Upvotes: 5