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
|
I'm trying to figure out a couple of things all related to drag and drop. I was trying to figure out how to drop an object onto the diagram surface. Ultimately I want to create a node from the object, but I do not have a DiagramToolBox so I'm not sure how to go about this. I have not tried to completely override the drop handling myself. I suppose I could do that. I was just curious if I could make use of the default implementation by putting the 'correct' info in the drag info. As I side issue to this, if I start dragging some object over the diagram surface, it shows that I am allowed to drop it on the diagram, even though there is absolutely nothing that will process this object when it is dropped. That is kind of weird. Another thing that might be interesting would be to be able to drop an object on a connection point. I am open to suggestions on this, I have been looking at the Node Builder class to see if I could figure out how to leverage that somehow. The one thing that bothers me a bit about this class is that there is no way to prevent a node from being created. In the examples I have seen on the forum others seem to be simply removing the last node created if they don't want it. Wouldn't it be simpler to just prevent the node from being created at all? |
|
|
Hello Eliz The DiagramSurface doesn't actually use the standard WPF drag/drop system for tool box items. The WPF drop support is enabled in the default style and was probably left over from the initial experiments. I will leave this for now to avoid breaking changes. The easiest way to drop arbitrary items on the surface and create nodes would be to listen to the DiagramSurface.Drop event. This will not interfere with built-in drag/drop functions from the tool box. In the event handler, you can get the logical point on the diagram at the mouse point using this code:
This uses the Drop event arguments (e) to get the position of the mouse from the top left corner of the DiagramSurface (ds) in pixels. This is run through the GetLogicalBounds method to convert it into the logical diagram position. You can then use the X and Y value from the output rectangle to define the bounds of the new node. Then instantiate a new node with the calculated bounds and any other properties you need to set, and add it to the diagram model. In the event handler, you can also use DiagramSurface.FindMouseOverElement and check if the result is a DiagramConnectionElement. Regarding custom node builders, the builders themselves add the created node to the diagram, so they can include logic within the CreateNode implementation and decide not to add the node. You shouldn't need to use node builder to implement your custom drag/drop support though. Let me know if you have any questions about this. -Jason Fauchelle |
|
|
Hi, After many other distractions I'm back to adding more support for drag and drop -such as dragging information on top of nodes and such. So I was looking at your suggestion above to use the standard Diagram drag and drop services and calling 'FindMouseOverElement' to determine what is below the mouse. My problem is that I never get anything back from the method except null. So I tried the various methods that seem to do similar things. Finally I was able to get something from FindElementAtPoint, but I fail to see why the others don't work. Am I doing something wrong?
Another thing I was looking at was processing the ToolThumb.QueryDropPositionEvent as I see in one of the samples. Is it possible to limit where the node is dragged to with this? In other words if there is a particular area that you want the node to remain in, can we prevent the node to be dragged outside that area? |
|
|
Hi Eliz, FindMouseOverElement calls FindElementAtPoint so it is odd that it doesn't work. I haven't looked into it, but my best guess is that the static Mouse.GetPosition method does not work correctly in a drag/drop scenario. As for your other question, I have not tried this, but you should be able to use ToolThumb.QueryDropPositionEvent to limit the placement of nodes. You can set e.DesiredPosition to do this. Another approach would be to put this logic within the nodes themselves - listen to when the Bounds change, and then adjust them if they are out of bounds. -Jason Fauchelle |
|