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 Jason, I created a Connections Collection change event, thanks to INotifyCollectionChanged cast. But I don't know how to bind a function to the 'DataChanged' event of the new created connection. Do you know how I can access to the last created DiagramConnection when the collection change? Thank you |
|
|
Hello Leon This partly depends on what you want to do after the data changes. One option would be to extend the DiagramModel class (and use an instance of your custom class when setting the Diagram of the DiagramSurface). In here you can hook up an event handler to the connection collection, which I think you are already doing. In that event handler, you should be able to iterate the NewItems property of the event args and attach an event handler to the DataChanged event of the connections. Note that you will first need to perform a null check on the NewItems property, and you should also iterate the OldItems property to remove the DataChanged event handlers from those connections - they are the connections that get deleted. Setting up an event handler in code would look something like this:
Removing an event handler is the same as above, but use -= instead of += And the event handler would be like this:
Let me know if you have further questions about this. -Jason Fauchelle |
|
|
Hello Jason sorry, I didn't write my question correctly. I wanted to ask you how I can access to DataChanged event when the connection is created. Actually I know when a Connection is created, thanks to the CollectionChange event of INotifyCollectionChanged. But then, in the called function, how can I access to the DataChanged event starting from the 'sender' object ? (I think 'sender' would be the Collection of Connections). I mean, how can I cast the 'sender' to access to the last created connection? Thank you |
|
|
Hello Leon Thanks for the clarification. You'll actually want to look at the event args in your event handler rather than the sender. You should be able to do something like this:
And then do the same for e.OldItems to remove event handlers. You are right, the sender will be the Connections list of the DiagramModel, but that will not be useful here as it does not log the recent most connection. In Visual Studio, you can put a break-point on lines of code, such as in an event handler, and then when you run the application and cause a connection to be added, VS will pause the debugging and you can hover the mouse over 'sender' and 'e' to see what they actually are. This will help you in other scenarios as well. Hope that helps. -Jason Fauchelle |
|
|
Thank you Jason, it works. |
|