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 would like to create a trigger that does the following: Whenever user dragging a connection from a ConnectionPoint, I would like to trigger individual ConnectionPoint validation and set each ConnectionPoint's color individually. For eg: Node1 contains 4 ConnectionPoint, Node2 contains 2 ConnectionPoint. When user drag from Node1:Point1 => Node2:Point1, it is valid, so colored it as Blue. When user drag from Node1:Point2 => Node2:Point2, is it INVALID, so colored it as Red. Is it possible to achieve such behaviour? Thanks. |
|
|
Hello I think the sample I have attached will demonstrate what you are looking for. To run this sample, make sure to include a reference to your copy of the Mindscape.WpfDiagramming.Foundation.dll. When you run it up, you will see 2 green nodes. Each node has a connection point on the top and bottom edges. The Data property of the top connection points have been set to "PortA" and the Data for the bottom connection points is "PortB". If you drag a connection from the top point of one node and hover the mouse over the other node, you will see the top connection point is green indicating that a connection can be made. But the bottom connection point is red because it is invalid. You probably already know that connection point validation is performed in a custom connection builder. This is demonstrated in the attached sample as well as the ConnectionPointValidation.FlowDiagrams sample that comes with WPF Diagrams. The styling is performed in the ConnectionPointThumb style in MainWindow.xaml. The trigger you'll be interested in is at line 59 - 66. The second binding in this trigger looks to see that IsToConnectionDragOver on the parent DiagramNodeElement is true. This indicates that the user is creating a connection and the mouse is being dragged over the node. The third binding in this trigger checks to see that the IsToConnectionDragOver property on the connection point thumb itself is false. This indicates that the validation logic returned false, and so the thumb is styled red. You can ignore the trigger at line 41 - 49. Let me know if you have any questions. Jason Fauchelle |
|
|
Hi, I have a few questions: The third binding in this trigger checks to see that the IsToConnectionDragOver property on the connection point thumb itself is false. This indicates that the validation logic returned false...
|
|
|
By the way, why the CanCreateConnection() seems to be having the opposite logic?
|
|
|
Hello 1) Yes, the IsToConnectionDragOver property on the connection point thumb holds the validation result. 2) Unfortunately I have not found a way to get this exact effect. I think that showing the validation states when the mouse is over the node rather than over individual connection point thumbs is more informative anyway though. Are you able to settle with this functionality for now? 3) The 2 null checks in the CanCreateConnection method are to handle the case when the connection is just being created or the mouse is not over a node. These should return true, otherwise the connection will not be created at all. You can change these to false and see the effect in the sample I sent you. The validation logic itself is performed in the last condition where it compares the Data. If none of the conditions are met, then false (invalid state) is returned at the end of the method. Jason Fauchelle |
|
|
Hi Jason, Thanks for your tips, I found another way to achieve the effect that I want on 2). Regarding 3), finally i understand the 'meaning' of it, as in the trigger: IsToConnectionDragOver is actually using the "CanCreateConnection" method to evaluate the ability to create connection (start drawing the lines). |
|