I need to somehow figure out which DiagramToolboxItem was the source of a newly added DiagramNode when the user drags a new diagram item in from the toolbox.
What's the best way to do this?
Hello Brandon,
Thank you for your post!
I have been looking into it and have created a small sample application for you. In the sample application I have handled the ItemAdded event of the XamDiagram. In the handler of the event I check if the added item is DiagramNode or DiagramConnection. Then I get accordingly the ShapeType or the ConnectionType.
Please find the attached sample application and feel free to let me know if you have any further questions on this matter.
Gergana, while I can certainly look at the ShapeType / ConnectionType, we are trying to do a little bit more than just shapes with this. I have certain properties in the ToolboxItem that I added which will dictate how the node behaves (and everything we have is a ShapeType = Rectangle). Ultimately I need to get the actual DiagramToolboxItem object that the new node drop came from.
A few options..
Any of the above scenarios would work, but ultimately we need to get the DiagramToolboxItem that the user dragged to create the node, not just the shape type.
Thanks!
Brandon
I have been further researching your questions. You can handle the PreviewMouseDown event of the DiagramNode. In order to handle it for every node you can create a style for the DiagramNode and handle it, using an EventSetter. This way you can get the DiagramNode, in the Toolbox, on which is clicked as follows:
private void node_PreviewMouseDown(object sender, MouseButtonEventArgs e)
{
DiagramItem item = (sender as DiagramItem);
}
Regarding your question about the 'last-clicked toolbox item' - you can create a collection of DiagramItems and in the PreviewMouseDown event you can check if the item already exists in the collection or not.
Please do not hesitate to let me know if you have any further questions on this matter.
I am just checking if you have any further questions on this matter. Please do not hesitate to let me know if you do.