My problem is as follows. I have a Canvas and I have a class called “Node”. I create a collection of Nodes, and for each Node I need to some shape (Ellipse, Triangle, Letter) on the canvas at some specific location.
When I click on a Node, I need to be able to go back to the parent Node object and change it.
Adding an MouseLeftButtonUp listener and then going to e.OriginalSource does not work because the original source is of type Ellipse (or some other Shape), not of type Node.
I see two solutions to this problem:
1) If there is some way to attach data to the Ellipse, such as a Node ID, that would be good (something like Ellipse.AddLogicalChild or Ellipse.SetCurrentValue, but I am not sure that would work or if it would be appropriate to use one of those methods).
2) Or, I need the Node to derive some Shape class so that I can add it to Canvas.Children directly.
How do I do either one of these? Or, if you see another solution, please let me know.
Thanks,
Anton Kanevsky
Your node class could just be a usercontrol that hosts the desired shape as its content. ie: Create the desired shape in the constructor and set as the content, then add the node to the grid.
Alternatively, you can just have the shape be a member of the node class(or not), and subscribe to the events with a node class function. ie: each shape would fire an event in its associated node class.