- > Do you need the 2012 VERSION?

 

UML elements on any UML diagram can be linked to another element, UML diagram, or parts of any other file by dragging. Open the linked item by double-clicking. This sample is an extension of Visual Studio Ultimate.

 

For example, you could:

 

You could extend this sample code to do more - for example:

The source code demonstrates a number of techniques:

How to run the sample

  1. You need:
  2. Download, unzip, open LinkModels.sln
  3. Press F5 to build and run the sample. 
    • The sample includes a test model, which will open in an experimental instance of Visual Studio.
  4. In any diagram in the test model, drag any of the following items onto any shape on the diagram:
    • Any file from Solution Explorer, in the same project or another project.
    • Any file from Windows Explorer.
      • Note that the link will stop working if you later move the solution and the target file into different relative locations. If you use source control, this means that it is advisable to link to files that are in source control; and even better to link to files in the same Visual Studio solution.
    • Any element from another UML diagram, in the same UML model (project) or another one. To do this, either display the diagrams side by side; or drag the element up to the tabs, across to the tab of the diagram where you want to drop, and then down to the shape you want to drop onto.

Easy Adaptations

You can easily adapt this sample code. For example:

Multiple Links

The sample code allows each element to be linked to only one item. But the IReference mechanism can accept multiple references. To adapt the code to allow multiple links:

URLs

The sample code lets you link URLs to an element. When you double-click the element, the URL opens in the VS browser. But to create a link to a URL, you have to follow a slightly odd procedure: first drag the URL from the address bar of your browser onto the Windows desktop, to create a .url shortcut; then drag the shortcut onto the UML diagram element; then you can delete the .url shortcut.

You could improve the code by discovering how to extract the URL from the IDataObject that is passed when the user drags from a browser's address bar directly onto the diagram. Bear in mind that different browsers might behave differently in this respect.

When you've cracked it, kindly post the result on the Visualization and Modeling SDK Forum.

Layer Diagrams

The sample code works only with UML diagrams, and not with layer diagrams. You could add code to let users link layers to other items. I'd suggest you consider the following points:

For more about the Layer API, see Creating Extensions for Layer Diagrams.

How to install the sample on other computers for demonstration purposes

To install the extension on other computers:

  1. The target computer must have Visual Studio Ultimate. It does not need VSSDK or VMSDK.
  2. Copy the VSIX file from bin\Debug to the target computer.
  3. Double-click the VSIX.

To uninstall it, use Tools>Extension Manager in Visual Studio.

You can work with models that contain links on computers where the extension is not installed. The links should not be lost.

 

Scope of the sample

This sample is provided solely for demonstrating techniques that you could use in your own programs. It has not been thoroughly tested.

Discussion and Feedback

Please post suggestions and questions in the Visual Studio Visualization and Modeling SDK Forum.

 

Related samples

Changes

Visual Studio 2012 version