This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
What is the best way to do the following:
Thank you! |
|
|
Hello Xiaochu 1) There are 2 main ways to watch connection deletions. One way is to cast the Connections property of the diagram model to an INotifyCollectionChanged. Then attach and event handler to the CollectionChanged event to listen to when connections are added or removed. Another way is to implement the IDiagramConnectionRemover class. The RemoveConnection method is called whenever the diagramming framework is deleting a connection from the model. You can set an instance of you custom connection remover to the ConnectionRemover property of the diagram model. This approach is convenient if you need to do some custom logic related to deleting the connection from the diagram. Below is how you would start implementing the RemoveConnection method. After this code, you can then do whatever custom logic you need to do as a result of removing a connection.
2) The best way to watch and respond to a connection relocation is to implement the IDiagramConnectionRelocator interface. The RelocateConnection method is called when the framework wants to perform a connection relocation. You'd start by implementing the RelocateConnection method like this:
Then after this code, you can perform any custom logic that you need. The CanRelocateConnection method can just return true. To use this, set an instance of your custom connection relocator to the ConnectionRelocator property of the diagram model. 3) Having non-connected connections sitting in the diagram is not a built in feature. However, in your custom connection relocator, you can check info.DropTarget.ConnectionPoint == null, which will mean that the user is relocating a connection but dropped it on nothing. You could then added a special invisible dummy node to your diagram, and connect the connection to that. This would produce the effect of having a non-connected connections. I haven't tried this much, so play around with this idea a bit, and let me know if you run into any trouble. Let me know if you need further help with any of these points. -Jason Fauchelle |
|
|
John, Thank you! The first two things worked perfectly. For the third thing, when info.DropTarget.ConnectionPoint == null, we can use info.DropTarget.ConnectoinEnd to tell which connection point is relocated, but how do I get the location of the new drop target, so that I can draw the invisible node there? Right now, I just add the invisible node to some distance off the original connection point. Could you please add a property Position to the DropTarget? A side question: The dummy node is created, but not added to the Nodes list. Will the memory of the dummy node be reclaimed if I do not reference it in my side of code. |
|
|
Hello Xiaochu Thanks for pointing this out. I've added the Position property to the drop target which will allow you to draw the node in the correct place. This will be available in the next nightly build. There won't be any memory issues with what you have described. Let me know if you run into any other road blocks as you implement this feature. -Jason Fauchelle |
|
|
Jason, it worked perfectly. And, with the same trick, I am able to delete a node, but the connecting connections still remain in the diagram. Thank you! |
|
|
Nice! Glad to hear you got it all working well. -Jason Fauchelle |
|