This tutorial shows how to use the Overview and NodeListView components.
Follow steps 1-5 from Tutorial 1: Getting started.
Add the following initialization code for the DiagramView, Overview, and NodeListView controls in the Index method of the HomeController.cs:
HTML Copy Code |
---|
diagram.ShowGrid = true; |
Setting the Diagram's ShowGrid property to true will display the alignment grid, and setting the AlignToGrid property will ensure the that the sides newly created nodes will be aligned to the nearest grid point.
The view's AllowInplaceEdit property defines whether items' text can be edited inplace.
The Overview's BackColor property defines the background color of the control and the DimColor property sets the color of the displayed diagram.
Use the NodeListView control's AddNode method to add an arbitrary number of nodes to its nodes collection.
Remove the call to the Diagram's HTML Helper method and add the following form declaration instead:
HTML Copy Code |
---|
@using (Html.BeginForm()) @Html.DiagramView(((DiagramView)ViewBag.DiagramView), new { style="width:700px; height:700px;" }) |
Upon form submission the DiagramView control will serialize itself in JSON format and will store the serialized string in a hidden field. This field will be added automatically to the form by the DiagramView control and will have a name matching the following pattern: DiagramViewId + "_PostData" e.g. "diagramView1_PostData". You can access the field through the Request.Form collection and pass the data to the DiagramView's FromJson method in order to keep the changes made from the client. The view's FromRequest static method can be used as a shortcut to achieve the same effect. Change the DiagramView control initializer as follows to persist the changes:
C# Copy Code |
---|
DiagramView view = DiagramView.FromRequest("diagramView1", Request); |
Run the application. Try drawing some nodes and/or links. Double-click on an object to inplace-edit it's text. Drag items from the NodeListView control onto the Diagram to create new nodes. Submit the form to see how the control will store your changes.
The image below depicts how the application would look like with some nodes and links added to the diagram.