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
|
Hello, I want to bind some properties of a source node's data context to the textbox which appears at the source end of connections(as default). Is there a way to accomplish this task? Also i may need another textbox at the destination end of a connection. How can I edit the structure connection like this way? Should i use control templates? Could you send me connection's default style xaml and maybe a simple example? Thanks for your help. |
|
|
Hello I have attached a sample that demonstrates a solution to both of your questions. To run the sample, make sure to add a reference to your copy of the Mindscape.WpfDiagramming.Foundation.dll. When you run up the sample, drag any 2 nodes from the tool box onto the diagram, then connect them together with a connection. You will see this connection has 2 text boxes, one at the source and one at the destination. Note that the source box is using a binding to a null property value so doesn't display any text at first. If you hover the mouse over the connection, you can see both text boxes. Now, click on the text box inside the source node, or the source connection box. Type something and you will see the same text appears in both the source node, and the source connection label. This of course is due to using a binding. To get a text box at both ends of a connection, I started by creating a new class that has 2 properties. One property stores the data for the source of a connection, and the other stores the data for destination of the connection. (If you will only be binding to properties on your node then you probably won't need this data object. It exists because I made this sample a while ago only to demonstrate a textbox at both ends of a connection). Connections have a Data property which I set to be an instance of this ConnectionData class. I set this using the ConnectionBuilder in the sample which is notified whenever the user is creating a connection. All the xaml resources are in MainWindow.xaml. The main connection style/template is at line 168. From line 200 to 223 are the 2 connection data presenters. They use multi bindings and a converter to calculate the positions of the presenters. Line 113 to 147 shows the templates for the connection presenters. These are TextBoxes with some DataTemplate triggers to disable them based on "read only" options from the diagram surface. They also have a trigger to set the border visibility based on mouse hover. The DataContext of these data templates is the connection model. The Text property of the destination text box is binding to Data.Destination. Data is the property on the connection model. Destination is a property on the ConnectionData class I mentioned earlier. For the source text box, rather than binding to the Source property of the ConnectionData, I am binding to FromConnectionPoint.Connectable.Data. This is how I bind the source display to the data of the source node. FromConnectionPoint gets the source connection point of the connection. Connectable gets the object that the connection point is attached to. This could either be a node or a connection. Then Data gets the data object of that node. From this you should be able to work out the bindings to your own properties. Let me know if you need more help with anything. Jason Fauchelle |
|
|
Hello. Thank you so much for your detailed reply. It helped very much. Now i need to choose different connection styles for different source nodes. Some connections should have two text boxes, some should have only one, and some sould have none etc. based on their source and connection nodes. What may be the best way to do this? If i copy all style i think it will be messy. Should I make different data templates and make a selection among them with some kind of connection node data template selector or else? If so, how can i do it? Also there is an issue about connection relocation. When I change a connection's source or destination node, connection type should change. What may be the proper way to do it? Thanks. |
|
|
Hello There are a couple of options here. One way would be to hide the source/destination content presenters when appropriate. (By setting their visibility). You could use triggers or/and converters to listen to the appropriate properties to decide which content presenters should be visible. To make this easier, you may want to encapsulate all the logic for this into your model and expose a single property on a custom connection implementation such as "ConnectionType". Then in the connection style in the sample I sent you, use triggers or converters to look at this one property to change the visibility of the presenters. This is the approach that I would start out with. The other option would be to make several templates, one for each "type" of connection. You can start off by pulling out the ControlTemplate of the connection style in the sample I sent you. Then make this ControlTemplate as a resource in the resource dictionary. Then copy the template a couple of times, give them different names and then modify them based on the different connection arrangements you need. One would have both content presenters, one would have only the source, one wouldn't have any. Then back in the connection style (which no longer has a control template because you pulled it out), use triggers to listen to properties on your connection model, then set the Template property of the connection to be the appropriate control template. To help choose which approach you should take: The second one would be good if you only have a few different connection "types", but each template may be very different from each other. The first approach is good if you have lots of different styling rules that can be active in all sorts of different combinations. Which ever you choose, let me know if you need help implementing this. As for the other issue you mentioned, Yesterday I fixed a bug that I think may be related. Namely, the FromConnectionPoint and ToConnectionPoint properties on the connection model now raise property change notifications. This fix is available in the current nightly build which you can download now. Nightly builds are available from here: http://www.mindscapehq.com/products/wpfdiagrams/nightly-builds. If this does not answer your question then I may have misunderstood the issue. If so, please give an example of what you mean. Jason Fauchelle |
|