Version

Dropping an Item from the Toolbox (xamDiagram)

Topic Overview

Purpose

This topic explains how a diagram item is copied when dropped on the diagram surface from the toolbox.

Required background

The following topics are prerequisites to understanding this topic:

Topic Purpose

This topic provides a general overview of the xamDiagram control.

This topic explains how to configure and use the xamDiagram diagram toolbox.

Overview

When the user drags a DiagramItem from the toolbox and drops it on the diagram’s surface or performs a copy-paste operation, the control creates a copy of this item. In addition the following item’s properties are also copied:

  • DragDropData - this property is copied using "shallow copy" - this process create a reference copies of the same object instance.

  • Content - this property is copied using "deep copy" - this process create object duplication using reflection by taking the advantage of the Activator.CreateInstance() method which means the duplicated diagram items will have their own instances of the mentioned property’s values. Keep in mind however that bindings and event handlers are not copied.

Note
Note

The "deep copy" duplication process involves creating of unknown (to the control) types. Such types can only be instantiated if a parameterless constructor is present.

Prevent Content Property Coping

In certain cases you may need to disable the deep coping of the diagram item’s Content property. To achieve this you need to follow these steps:

  1. Create a custom class which extends from either DiagramNode or DiagramConnection

  2. Override the Clone method

  3. In the new Clone method invoke respectively the CloneDiagramNodeProperties or the CloneDiagramConnectionProperties method

  4. Set the last boolean argument to false

The following code example demonstrate how to prevent coping of the Content property of a DiagramNode:

In C#:

public class CustomDiagramNode : DiagramNode
{
    public override DiagramItem Clone()
    {
        var newCustomDiagramNode = new CustomDiagramNode();
        CloneDiagramNodeProperties(this, newCustomDiagramNode, false);
        return newCustomDiagramNode;
    }
}

In VB:

Public Class CustomDiagramNode
    Inherits DiagramNode
    Public Overrides Function Clone() As DiagramItem
        Dim newCustomDiagramNode = New CustomDiagramNode()
        CloneDiagramNodeProperties(Me, newCustomDiagramNode, False)
        Return newCustomDiagramNode
    End Function
End Class

Related Topics

The following topics provide additional information related to this topic.

Topic Purpose

This topic provides a summary of all user interaction tasks in the xamDiagram control.

This topic explains how to use the commands provided by xamDiagram in UI elements such as menus and buttons.

This topic explains how to use the context menu provided by the xamDiagram control.

This topic explains how to configure the mouse interaction and tool for the xamDiagram surface.

This topic explains how to change the keyboard shortcuts associated with xamDiagram commands.

This topic explains how to configure the Undo/Redo operations in the xamDiagram control.

This topic provides information on how to restrict certain user interactions of the xamDiagram control.