Newbie to go:Diagram - Disable Drag/Drop

Please bear with me, I’m new to these tools so my question might be obvious answer…

Basically I have the following code, a diagram with a layout within containing two datatemplates. See below:

            Grid.Column="2" Grid.Row="1"
            NodeTemplateDictionary="{StaticResource NodeTemplateDictionary}"
            LinkTemplate="{StaticResource LinkTemplate}">
                    <golayout:TreeLayout FlowDirection="RightToLeft" Arrangement="Horizontal" NodeSpacing="20"/>
                    <gotool:DraggingTool DropOntoEnabled="True" />

I want to disable the ability for a user to select either data template and drag and drop them…

also trying to put a scrollviewer control around the Diagram but
although I set the height and width to 600x600, the height resets to 50.

thinking there is a property or attribute on the diagram markup where
one can specify if datatemplates in the diagram are selectable … ie
drag/drop…I know about AllowSelect which does freeze the datatemplates on the diagram, however it also locks any items from my pallette that I drop into the diagram.

Thx for the help

We’ve moved this post from the GoDiagram forum to this GoXam forum. Sorry if you thought you had to repost…

The default ControlTemplate for Diagram includes a ScrollViewer, so you don’t need to add one yourself. (You can see the ControlTemplate by looking at the Generic…XAML file in the docs subdirectory.)

You already know about setting Diagram.AllowSelect. You can disable the selectability of individual parts by setting the attached property go:Part.Selectable=“False” on the root visual element of the DataTemplate. Or data-bind that attached property to whatever you want.

You can control whether individual parts accept any drop-onto by setting or data-binding the go:Part.DropOntoBehavior attached property. It defaults to “None”.

thx for the heads up, I wasn’t sure what happened to my post.

Anyways, thx for the advice, I added the scrollviewer and also the Selectable attribute.

Thx alot for the answer and fast response!

now I see another issue that I’m been trying to work through for the past few hours…

when I drop a item from my palette onto my datatemplate an event fires that centers both of my data templates with the item from my pallette in the middle…any ideas?

If I understand you correctly, you want to position a dropped node so that it is centered on the node that it was dropped upon. Is that right?

If so, it’s probably easiest to customize the DraggingTool. In the constructor set DraggingTool.DropOntoEnabled.

Override DropOnto. It normally checks for DropOntoEnabled, looks for a Part at the given Point, and then decides what to do based on the Part.DropOntoBehavior. Because you are overriding this method you can ignore the DropOntoBehavior, unless you are also depending on that property for other cases.

I haven’t even compiled the following code, but it ought to be something like:

[code] protected override void DropOnto(Point pt) {
Diagram diagram = this.Diagram;
if (diagram == null) return;
DiagramPanel panel = diagram.Panel;
if (panel == null) return;
IDiagramModel model = diagram.Model;
if (model == null) return;
var parts = this.CopiedParts ?? this.DraggedParts;
if (parts == null) return;

  if (this.DropOntoEnabled && model.Modifiable) {
    Node target = panel.FindElementAt<Node>(pt, Diagram.FindAncestor<Node>, p => ConsiderDragOver(pt, p), SearchLayers.Nodes);
    this.DragOverPart = target;
    if (target != null) {
      Rect nbounds = target.Bounds;
      foreach (Part dragged in parts) {
        Node draggednode = dragged as Node;
        if (draggednode == null) continue;
        Rect dbounds = draggednode.Bounds;
        draggednode.Position = new Point(nbounds.X+nbounds.Width/2-dbounds.Width/2, nbounds.Y+nbounds.Height/2-dbounds.Height/2);

Note that it handles multiple selection, positioning all of the dragged nodes in the same manner, centered on the target node.

sorry for not properly explaining myself…currently I have two datatemplates that appear like this:

| | | |
| | | |
| | | |
| | | |
| template 1 | | template 2 |
| | | |
| | | |

| | | |

| | | |


when i drop an item from my palette onto a node on template 1, both templates center in the middle of the canvas w/ the new item from the palette in the middle. I want the templates to stay in static positions, w/ the item from the palette connected to whatever node I drop it onto…

does that make sense?


I’m sorry, but I still don’t understand your situation. Is your sketch what your whole diagram looks like?

First, DataTemplates are never seen in a Diagram, because they are always “applied” – their elements are copied into the diagram’s visual tree. So when you show “template 1” on the left side of your diagram, is this an instance of a Node? And is “template 2” on the right side another Node?

Second, how did they get positioned there? Did you explicitly set their Node.Location?

If all of the above assumptions on my part are correct, perhaps what is happening is that the Diagram.Layout is repositioning your two nodes. If you don’t want them to be laid out by the diagram’s layout, just set the attached property go:Part.LayoutId=“None”.

I’m apologize for the bad translation, I’m still pretty new to GoDiagram.

Here is the right terminology and the issue


| go:Palette | go:Diagram |
| node 1 | | | |
| node 2 | start node | | end node |
| node 3 | | | |

| node 4 | | | |


I’m dragging a node from the palette onto the start node.

Both start & end node are specified with static positions in my flowchart.xml. See below:

<?xml version="1.0" encoding="IBM437"?>

I added g:Part.LayoutId = “none” to bot the start & end node as shown below:

<go:NodePanel MinHeight="620" MinWidth="70" Sizing="Auto" go:Part.LayoutId="None" go:SpotPanel.Main="True">

When I did this both start & end nodes stayed in their original position, but when I do a link port on the start node to the new node port the Link goes down to the bottom of the diagram and then back up to complete the linkage instead of going straight from the start node to the new node that I dropped

Thx for ur help & patience

go:Part.LayoutId, like most attached properties, must be set on the root visual element of the DataTemplate. That means on the SpotPanel, not on the NodePanel, in your particular example. I’m surprised that it had any effect, actually.

Are you using links with Route.Routing=“AvoidsNodes”? If so, maybe it’s trying to avoid going over some node(s) that are in the background. You might want to mark all of those decorative nodes with go:Node.Avoidable=“False” – basically on any Node that you don’t mind having a link run through. (And as usual, it’s an attached property that goes on the root visual element of the node’s DataTemplate.)

I removed the AvoidNodes routing and works great…I may to add it back in the future since I don’t want Links going over nodes that are in the diagram, but for now it’s fine.

To give you an idea of what I’m playing with, here’s a couple screenshots.

Without Route.Routing=“AvoidsNodes”

Uploaded with

With Route.Routing=“AvoidsNodes”. On this I don’t understand why the link is acting in this way, there is no node to avoid, but still it is avoiding something.

Uploaded with

Although I haven’t tested that particular case with the odd FromSpot, I suspect that that routing behavior has been avoided in version 1.2.