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
|
Hi, I want to achieve an effect of snapping the connection to a port on an custom element node when user wanted to create a connection. How can I detect the event whenever user start dragging a connection from one node to another? How a node discover that when a connection is being dragged over it?
Thanks. |
|
|
Hello One way to know when a connection has started to be created is by adding an event handler to your application that listens for the DragStarted routed event. So somewhere in the application window code you could write: AddHandler(Thumb.DragStartedEvent, new DragStartedEventHandler(OnConnectionStarted)); And then include the following method:
private void OnConnectionStarted(object sender, DragStartedEventArgs args) This will listen to all Thumb controls, not just the ones used to create connections. You can get around this by having a check in the event handler method to see if the 'sender' property is a ConnectionPointThumb control. As for the nodes: The DiagramNodeElement class has a property called 'IsToConnectionDragOver' which is true if a connection is being dragged over the node. This should give you a place to start, but I'm not sure if it is enough information for you to complete the effect you want to implement. Let me know if you need more. Alternativly, if we discuss some more finer details of this effect, I may be able to implement it for you within the core of WPF Diagramming if its not application specific. Regards |
|
|
Hi, I tried added the handler to my editor's code behind, but it doesn't return me with the correct 'sender' object. For instance, in my code behind,
this.DiagramSurface.AddHandler(Thumb.DragStartedEvent, new DragStartedEventHandler(OnConnectionStarted)); It will always return me with the "DiagramSurface" object whenever the drag event occured. Can you provide an example how to work this out correctly? Thanks. |
|
|
And, the "IsToConnectionDragOver" doesn't work for me. It always return false although my mouse is on the elementl. :/ |
|
|
Right, sorry about that, to get the ConnectionPointThumb you will want to use DragStartedEventArgs.OriginalSource. The IsToConnectionDragOver property should be working, remeber it can only be true if you are dragging a connection, not just by moving the mouse over the node. In anycase, here is another approach you could take for listening to when the connection is dragged over a node: Create a new class that extends the FlowDiagramConnectionBuilder. The CanCreateConnection method that you override is called ever time the diagram surface is checking if a connection can be made between the connection point that the user started dragging from, and the node that the mouse is over. You can use the method arguments to find the start and end nodes. Let me know if you have any questions about this. Regards |
|
|
Hi, sorry, I still can't get the "IsToConnectionDragOver" property to work. I tried out on a sample project, you can see the code in main.xaml.cs, maybe you can help me out with the sample project. Regarding the FlowDiagramConnectionBuilder, how are you going to use method arguments to find the start and end nodes? I thought those parameters are the ones tha we need to pass in?
|
|
|
Hello The FlowDiagramConnectionBuilder.CanCreateConnection method is called by the WPF diagramming foundation. So by overriding this method you will have access to the method parameters that are passed in. You can cast fromConnectionPoint.Connectable to get the start node, and cast dropTarget.Connectable to get the node that the mouse is over. I'll look into your sample now. Regards |
|
|
Hello seems I missunderstood what you are trying to do with the IsToConnectionDragOver property. The code in your sample is looking through all the nodes only when a connection is started to be created. That is, only when the user presses the mouse down on the connection point. If you want to get the node where the connection is being started, then you can use ConnectionPointThumb.ConnectionPoint.Connectable. Or if you want to find the node that the mouse is over while the mouse is moving around, then you could listen for Thumb.DragDelta routed events and use the same foreach loop you are using now. The performance will be better by using the FlowDiagramConnectionBuilder approach though. Let me know how you want to go ahead. - Jason |
|
|
Well, thanks for your prompt reply. I would appreciate if you can guide me through the approach using FlowDiagramConnectionBuilder. :) |
|
|
Sure no problem, but before continuing, I would like to know what the final result of this will be. Do you want the user to drag a connection over a node, and then have a connection created to closest connection point when the mouse is released? Or are you wanting to snap the blue connection line to the closest connection point while the mouse is still hovering over the node? or is there more to it? Cheers |
|
|
Well, the first case is my initial intention. But I would appreaciate much if you can show me the second case as well. :)
|
|
|
In that case, it will be easier if I implement this feature into the WPF diagramming foundation. I can have it in the nightly builds tonight. I'll have to pass on the second case though, the blue connection line is in the adorner layer which could make it tricky to snap to connections. Or would you like me to explain the FlowDiagramConnectionBuilder technique instead? You would also need to listen for when the mouse is released over a node which will start to get a bit messy. - Jason |
|
|
I have implemented this feature as described in the first case. So if you drop the connection on a node rather than a connection point, it will create a connection to the closest connection point on that node. This will work with both connection creation, and connection relocation. This update will be available through the nightly builds from tomorrow the 2nd of March. Let me know if it is what you expected, or if we need to implement more. Regards |
|
|
Well, in that case, I'll just wait for your nightly then. The second case seems to be a bit tricky, I'll just focus on get my first case done first. ;) Thanks a lot for your support. Do let me know once the feature is ready, and how can i utilize it. :) |
|
|
This feature (for the first case) is available now through the current nightly builds download. Try it out and let me know how it goes. - Jason |
|
|
Hi Jason, it works great now! thanks for the update. :) |
|
|
I read this discusion. And I have a similar problem. I store in FlowDiagramConnectionPoint.Data some information. If the information equal at a source and at the destination, then connection is possible, else it is impossible. I write public bool CustomConnectionBuilder.CanCreateConnection(...)
This method works normally. Imposible connection are not created.
Question: How can i highlight on mouse drag: by red - impossible connection points and by green - possible connection points?
P.S. I using custom ConnectionPointStyle like this http://www.mindscapehq.com/forums/Post.aspx?ThreadID=3251&PostID=10838
|
|
|
Hello This should be possible by playing around with the triggers on the Style and ControlTemplate of your custom connection point style. I have attached a text file containing a connection point style similar to the one you mentioned which achieves the effect you want. Use this style to modify your own style by changing the triggers. If you have troubles getting it to work then let me know. Unfortunatly there is one case which I could not get to work. That is when you start dragging a connection from a node that has several connection points, any connection points on the node that you started dragging from that are "impossible" do not turn red. All other nodes work fine, it's just the node where the connection originates. At the moment there aren't any satisfactory hooks for this case. Try out the triggers that I have made so far, and then let me know if this case will be a problem and I will see what can be done. - Jason |
|
|
Thank you, Jason. |
|
|
I see problem with connection points at same node.
|
|
|
Hello Shuraz I have now added support for connection point validation styling on the node that is originating the connection. First you will need to download the nightly builds from tomorrow the 21st of May. Next, add this trigger with the control template triggers in the style that I gave you last time:
<MultiDataTrigger> Note this is for the control template triggers not the style triggers. And do not remove the other control template trigger from the style I gave you, it is still needed. From what I can see, this now fully achieves the effect that you described. Let me know how it goes. - Jason |
|
|
Thank you, Jason. Coloring of point is good. But there was one problem: If i start dragging connection to other node, inbound connection points of current node are visible. How can i collapse theirs? Inbound connection points must be visible only on destination node.
The given problem is present at your style.
In a attached file my own style, I hope all in it correctly. |
|
|
Hello Shuraz I have modified the internal logic of the connection point thumb yet again which will now support all your current specifications. First download the nightly builds from tomorrow the 25th of May. Then you can use the new set of control template triggers seen in the attached file. The first and last ones are similiar to what you have already seen, the second trigger collapses the connection points on the current node if it is not the destination. (the IsMouseOver condition still listens for a value of "True" because while creating a new connection, the current connection point captures the mouse) Let me know how it goes |
|
|
Thank you, it's worked. |
|