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
|
Ok, now I have a class from which I want to instantiate objects and attach to flow diagram nodes. I want to use the standard flow diagram nodes. When the user drags a node from the palette on to the drawing surface...this is the moment I want to attached a newly created object, initialized to defaults. The class looks something like this...
The class properties would be displayed in the flow diagram node using a custom data template. I already know how to do this because of the answer to a previous question I posted in this forum. What surprises me is there does not seem to be any events generated from either the diagram surface or the diagram interface that would signal the creation of new nodes or connections in the diagram. If I could connect to such an event, then I could attach my workflow element object to the newly created diagram node. What is the proper way of setting the Data member for newly created DiagramNodes? Regards, Bob Rundle |
|
|
Ok...made some headway. I created 2 shim classes for FlowDiagramModel and FlowDiagramModel.Nodes...
and
So when I drop a flow diagram node on the surface, I can set the Data property in Add or Insert...
It all works. But man this is butt ugly. Surely there is a better way to do this. I had to write 79 lines of code just to attach my own object model to the diagram node. Where is the elegance? Regards. Bob Rundle |
|
|
Hello Bob Apologies this part is not obvious. The easiest way to do this in your scenario is to cast the Nodes collection of the FlowDiagramModel into an INotifyCollectionChanged. Here you can attach an event handler to listen to whenever a node is added to the diagram - then set the Data property as you like. A simple solution but not easy to find. I've made a note to improve the disscoverability in the next version. Jason Fauchelle |
|
|
Yes, of course. I should have seen this possibility when I constructed the nodes shim class. You cannot discover this from the documentation! The documentation indicates that is derived from IList when in fact it is more than that...it is an ObservableCollection. The most obvious approach was to define the node dropped event for the diagram node tool and this does not appear to work.
|
|
|
This event gets handler by the DiagramSurface which is why you can't get it to work. IsHandled is set to true for nested DiagramSurface scenarios to work. I've made a note to improve this event too. If you did want to use this event, you can attach a handler to the DiagramSurface as seen below. This is more convenient than setting it on every single node tool:
and the event handler:
In your scenario, it is best to listen to the collection events as it is a single place where you can handle both user changes and programmatic changes made to the diagram. Jason Fauchelle |
|