Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Ok this is a fairly common error and I'm aware that basically I'm adding twice the same path to the canvas.

The problem is that I have a "dummy path" (let's call it pathDummy) which is added several times to the canvas any time changing it's geometry (that is its set of points). This is how I have to deal with it and can't remove it all the times.

So I tried to make a new path from pathDummy by doing:

System.Windows.Shapes.Path newPath = SelectedPath;
paths.Add(newPath);
plotCanvas.Children.Add(paths[paths.Count - 1]);

but that didn't solve the problem. So what is that stays the same in newPath and generates the error? thanx for any help
Posted

1 solution

You haven't created a new path from the selected path; you've just stored the selected path in a new variable. That gives you two variables looking at the same instance of the class, not two instances of the class.

To create a new instance of the Path class, you need to use the new keyword to create a new instance, and copy over the relevant properties:
C#
var newPath = new System.Windows.Shapes.Path
{
    Data = SelectedPath.Data,
    Fill = SelectedPath.Fill,
    Stroke = SelectedPath.Stroke,
    ...
};
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900