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
|
Is it possible to detect when a node has been dragged/dropped over a connection? When this happens, I would like to highlight the connection. If the user chooses to drop the node onto the connection, I would like to insert the dropped node between the two connected nodes. For example:
Is there a way to do this? Thanks! |
|
|
Hello This is possible, but you'll need to implement this logic in your application - it isn't a built in feature. The tricky part is finding the connection that the node is being dragged over. At the moment, you'd need to iterate all the connections in the model, and check to see if the node bounds intersects with any of the segments. We are currently working on WPF Diagrams 3.0 which will feature huge performance improvements. From this, we'll be able to include helpers for you to get connections that a node drags over. I recommend waiting until this next version is released (quite soon) and I'll send you a sample demonstrating how to implement all this functionality. The rest of this logic is very straight forward. You can edit the diagram model through the IDiagramModel.Connections and .Nodes collections. Nodes have a ConnectionPoints property which gets you all the connection points on the node which you can use to attach or remove connections. I'll keep you posted as to when 3.0 is released. Jason Fauchelle |
|
|
Hello We have just released WPF Diagrams 3.0 which will make it easier to implement the logic you described. More information about the release can be seen in this blog post: http://www.mindscapehq.com/blog/index.php/2012/12/12/just-released-wpf-diagrams-3-0/ I have attached a sample demonstarting the basics of implementing the logic you want. To run the sample, make sure to add a reference to the Mindscape.WpfDiagramming.Foundation.dll from version 3.0. First I implemented a custom connection to include the highlighting logic. This can be seen in the HighlightingConnection class in the Model folder. This simply extends our base DiagramConnection class and includes the IsHighlighted property. Then I implemented the ConnectionBuilder class - also found in the Model folder. This implements the IDiagramConnectionBuilder interface which is used to build instances of the HighlightingConnection and add them to the diagram. An instance of this is used to set the Diagram.DefaultConnectionBuilder property at line 37 of MainWindow.xaml.cs. The default connection builder means that when you drag a connection point on a node, it will create an instance of the custom connection implementation. In MainWindow.xaml.cs I attach a few event handlers to the DiagramSurface to listen to node movement events. The ToolThumb.QueryDropPositionEvent will be raised whenever a node is being dragged from the toolbox, or when an existing node is being dragged on the DiagramSurface. The event handler for this manages all the highlighting logic - finding the connection that the node moves over, and setting the IsHighlighted property of the approprtiate connections. The DiagramSurface.GetConnections method called at line 75 is new to Diagrams 3.0. This takes a Rect and returns all the connections that intersect it. The MoveThumb.DragCompletedEvent is raised when an existing node has been dragged and dropped somewhere else on the DiagramSurface. Also, attaching an event handler to CollectionChanged of the Diagram.Nodes collection lets you listen to when a new node is added to the diagram. Both these event handlers in MainwWindow.xaml.cs call the ConnectNode method which performance the main connecting logic - removes the previous connection and adds in the 2 new connections. The logic I have implemented for this is fairly hard coded. i.e. it simply connects one connection to the top of the node, and one to the bottom of the node. You can adjust this to suit the requirements of your business logic. I have put comments in the sample that you can follow to help understand what's going on. If you have any further questions, let me know. Jasonn Fauchelle |
|