When building a drag and droppable org chart, I have a go:Palette in the left pane and go:diagram on the right. I would like to put another control in the palette such as a TreeView control. User would be able to drag and drop a TreeView node to the org chart on the right. Is this doable? I don’t think I can put stackPanels inside the go:Palette.

If you want to drag-and-drop from a TreeView to a Diagram, consider this topic: http://www.nwoods.com/forum/forum_posts.asp?TID=3538<span style=“font-size: 11pt; font-family: “Calibri”,“sans-serif”; color: rgb(31, 73, 125);”>

You said in the other thread that "There is "common" drag-and-drop support in the Silverlight Toolkit from silverlight.codeplex.com. I know that that works with GoXam, from TreeViews to Diagram." I am using a SilverLight toolkit treeview control in the palette. I am wondering what is the mechanism in GoXam to catch the dragged tree node(s). I tried ExternalObjectsDropped and it didn't catch the dragged part/event. Thanks for the help.

There is no support in GoXam for the toolkit’s drag-and-drop mechanism; we could not build such a dependency into our DLL.

The support that we do provide, such as drag-and-drop from Palette to Diagram, we implemented privately, so that is able to use the Diagram.ExternalObjectsDropped event and the diagram’s DraggingTool.

To use the toolkit drag-and-drop, just treat the Diagram like any other target Control. You can use the DiagramPanel.TransformViewToModel method to convert a mouse point into model coordinates.

Do I have to put the treeview (either the toolkit treeview control or the Telerik RadTreeView for SilverLight) in go:Palette in order to make it work? Right now, I was unable to catch the drag and drop event in the diagram panel on the right.

No, I was assuming you wanted to use a TreeView by itself and not a go:Palette at all.

See this page, you will get more idea. http://www.dotnetspark.com/kb/1663-silverlight-drag-and-drop-listboxitem-to.aspx
Walter is correct. Use Telerik RadTreeView instead of go:Palette.
For dragging:
RadDragAndDropManager.AddDragInfoHandler(treeView, OnDragInfo);
RadDragAndDropManager.AddDragQueryHandler(treeView, OnDragQuery);
Then implement your OnDragInfo and OnDragQuery methods.
I am not sure the drop. You may try this
RadDragAndDropManager.AddDropInfoHandler(myDiagram, OnDropInfo);
RadDragAndDropManager.AddDropQueryHandler(myDiagram, OnDropQuery);
Then create OnDropInfo and OnDropQuery methods, put break points in these 2 methods, run you app. If it stops in these break points, you can implement them.
BTW: make sure your diagram AllowDrop = true;

I have updated the post about external drag-and-drop to describe how to drag from a Silverlight TreeView to a Diagram using the Silverlight Toolkit’s support for drag-and-drop.

Thanks for all the help here.

I was able to drop a node from a TreeView to the org chart diagram with some of the code you showed on the other thread referred above except the new node is not connected to the org chart diagram. It is hanging on the side as an orphaned node. What do I need to do to link the new node with the current org chart diagram? <?:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

I need to know which node (the one on the diagram) it is dropped on to and set the node as its parent. Then the node will show up as a child node to the org chart diagram. But I am not sure how to get the id of the node on the diagram when a new node is dragged over.


In version 1.2, you can call DiagramPanel.FindPartAt(myDiagram.LastMousePointInModel, null, SearchLayers.Nodes).

In earlier versions you do the same thing by calling DiagramPanel.FindElementAt.

Thanks. It works, but not consistently. Looks like it sometimes found a node in the org chart diagram and links to it as a child node and sometime it missed it. And also, it is more likely to find the left most node on the diagram. Is there a better way to pinpoint a node on the diagram when it is being dropped onto? Here is my code snippet.

foreach (OrganizationNode draggedItem in draggedItems)
Part thePart = orgChartDiagram.myDiagram.Panel.FindPartAt(orgChartDiagram.myDiagram.LastMousePointInModel, null, SearchLayers.Nodes);
orgChartDiagram.myDiagram.StartTransaction("Dropped Data");
var newData = orgChartDiagram.myDiagram.Model.AddNodeCopy(draggedItem) as OrganizationNode;
if (thePart != null)
Node theNode = thePart as Node;
OrganizationNode myNodeData = (OrganizationNode)theNode.Data;
newData.ParentKey = myNodeData.NodeID;
orgChartDiagram.myDiagram.CommitTransaction("Dropped Data");

I’d guess that you really ought to find the existing Node before you start adding any new nodes, in case they overlap or get moved because of a layout.

Actually, the code above was not the problem. I was trying to make sure that dragged node(s) are showing on the diagram. I have updated the logic to only add data to the model if a parent node (on the diagram) is identified. But it still does not work right. It looks like that orgChartDiagram.myDiagram.Panel.FindPartAt(orgChartDiagram.myDiagram.LastMousePointInModel, null, SearchLayers.Nodes) cannot always find the part that the mouse is last released from and also the point almost behaves like a static property where it retains the last selected node in repeated tests.

If the drag doesn’t actually go over the Diagram then yes, the code will continue to use the last known point, which is Diagram.LastMousePointInModel.

I notice that this happens when the drop occurs outside of the Diagram, which seems like a bug in Silverlight Toolkit drag-and-drop. I guess that warrants further investigation.

But when the drop happens in the Diagram, it always goes where it should.

But my treeview is Telerik RadTreeView and RadDragAndDropManager not the toolkit TreeView. Would you take a look of my prototype sample project?

Sorry, I don’t have the time right now…

OK. I feel it is a bug in Panel.LastMousePointInModel. I am not sure how does it decide what the lastMouse event is during a drag and drop operation. It misses finding a part most of the time with Part thePart = myDiagram.Panel.FindPartAt(myDiagram.LastMousePointInModel, null, SearchLayers.Nodes);

Looking at the description of LstMousePointInModel, it says "Gets or sets the latest point in model coordinates at which any mouse event occurred" in goXam's documentation online. What is this coordinate relative to? Do you have an example of this to show its working?

The Diagram.LastMousePointInModel is in model coordinates – the coordinate system used by Parts and typically saved in data (if saved at all). It has the transformed Point of the last known mouse event.

Of course if the Diagram/DiagramPanel doesn’t get any mouse events, or if there are mouse events passed to other controls, it won’t know about them.

Are you sure that there aren’t any parts in front of the part you care about? That might cause the call to FindPartAt to return an unexpected Part, typically the one that is being dragged. You can use FindPartsAt (note the plural form) to find all of the parts at that point in model coordinates, not just the one in front.

The other post that I mentioned above shows Silverlight code using the Silverlight Toolkit for drag-and-drop support.

I think I know what the problem is now. Telerik TreeView has a drag Cue that follows mouse movement during drag and drop operation. It must be the drag cue intercepted the mouse move event so the underlying diagram does not get the mouse event. Does goXam diagram component handle tunneling RoutedEvent from a different control? I understand that RadControls implemented RoutedEvent tunneling.<?:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />