Basic Input and Output

Basics of Input and Output

Graphs can be saved and loaded into your application. The standard format used by yFiles is the GraphML format. GraphML is an XML format that can save graph structure, styles, and custom data.

Input and output work out-of-the-box for built-in graph elements and styles. To load or save custom data and styles, you may need to enhance the I/O process.

I/O functionality is enabled by default for programmatic use. Interactive use has to be enabled separately.

Enabling Input and Output for Interaction

Before you can interactively save or load a graph using the default keyboard commands, file operations must be enabled on the graph control. This is done by setting

FileOperationsEnabled to true:

Example 3.30. Enabling File Operations

// Enabling saving and loading the graph using commands.
graphControl.FileOperationsEnabled = true;

Using Input and Output

The current graph can be saved by the graph control and loaded into the graph control using the following methods:

Table 3.49. Saving and Loading a Graph

Method Description
SaveFile Possibly opens a file dialog that lets the user choose where to save the graph. Saves the graph to the last known location or the chosen file.
SaveFileAs Opens a file dialog and saves the graph to the selected file.
OpenFile Shows an open file dialog and loads the chosen file.

Once file operations have been enabled on the graph control, the following commands can be used:

Table 3.50. File Operation Commands

Command Description
Save Possibly opens a file dialog that lets the user choose where to save the graph. Saves the graph to the last known location or the chosen file.
SaveAs Opens a file dialog and saves the graph to the selected file.
Open Shows an open file dialog and loads the chosen file.

Customizing Input and Output

GraphMLIOHandler is the class that handles save and load operations. To be able to save custom data and styles, you need to customize GraphMLIOHandler.

For a thorough explanation of working with GraphMLIOHandler, see the section called “Reading and Writing Graph Structure Data Using GraphML” and the yFiles for Silverlight tutorial, especially step 13.