Quantcast
Channel: DevExpress Support Center (Examples)
Viewing all articles
Browse latest Browse all 7205

How to: Create a DiagramShape Descendant with Editable and Serializable Properties

$
0
0
This example demonstrates how to serialize custom data using DiagramControl's serialization mechanism. In the example, the Content property of diagram shapes is loaded from data objects every time the diagram is shown. To associate shapes with data objects, the DatabaseObjectID property is added at the DiagramShape descendant level. To serialize this property along with standard DiagramShape properties, perform the following steps:

1) Mark your custom property with the XtraSerializableProperty attribute:
[C#]
[XtraSerializableProperty]publicintDatabaseObjectID{get;set;}


2) Call the ItemTypeRegistrator.Register method to register your custom shape type for serialization:

[C#]
DiagramControl.ItemTypeRegistrator.Register(typeof(DiagramShapeEx));

Note:
In certain scenarios, it is easier to use the DiagramShape.Tag property to store custom data without creating DiagramShape descendants. In this case, no further steps are needed as the Tag property is serialized by default.

To edit your custom property in PropertyGridControl, create a DiagramShapeController descendant and override the GetEditablePropertiesCore method. In this method, add your property to a collection of editable properties:

[C#]
protectedoverrideIEnumerable<PropertyDescriptor>GetEditablePropertiesCore(){varownerType=typeof(DiagramShapeEx);returnbase.GetEditablePropertiesCore().Concat(new[]{DependencyPropertyDescriptor.FromProperty(DiagramShapeEx.DescriptionProperty,ownerType),});}

Viewing all articles
Browse latest Browse all 7205

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>