How can I add a custom property to the Diagram? How can I display the property in the Property Editor?
How can I add a custom property to the Diagram? How can I display the property in the Property Editor?
The sample included in this Knowledge Base article demonstrates how you can add a custom property to the Diagram and also display it in the the Property Editor. This sample uses a derived Diagram (MyDiagram) whose CreateModel method is overridden to use a derived Model (MyModel). MyModel’s SetDefaultPropertyValues is overridden to add the new MyCustomProperty property using the SetPropertyValue method. This property is displayed under a new category and also includes a description.
When you build and run the sample you can now see the new property (MyCustomProperty) in the Property Editor in the MyProperties category.
[C#]
//Derived Diagram public class MyDiagram: Syncfusion.Windows.Forms.Diagram.Controls.Diagram { public override Model CreateModel() { return new QuickStart.MainForm.MyModel(); } } //Derived Model where the new property is added public class MyModel: Syncfusion.Windows.Forms.Diagram.Model { public override void SetDefaultPropertyValues() { base.SetDefaultPropertyValues (); this.SetPropertyValue("MyCustomProperty", 0); } [ Browsable(true), Category("MyProperties"), Description("Description for MyCustomProperty") ] public int MyCustomProperty { get { object value = this.GetPropertyValue("MyCustomProperty"); if (value != null) { return (int) value; } return 0; } } } |
[VB.NET]
//Derived Diagram Public Class MyDiagram Inherits Syncfusion.Windows.Forms.Diagram.Controls.Diagram Public Overrides Function CreateModel() As Model Return New QuickStart.MainForm.MyModel() End Function 'CreateModel End Class //Derived Model where the new property is added Public Class MyModel Inherits Syncfusion.Windows.Forms.Diagram.Model Public Overrides Sub SetDefaultPropertyValues() MyBase.SetDefaultPropertyValues() Me.SetPropertyValue("MyCustomProperty", 0) End Sub 'SetDefaultPropertyValues _ Public ReadOnly Property MyCustomProperty() As Integer Get Dim value As Object = Me.GetPropertyValue("MyCustomProperty") If Not (value Is Nothing) Then Return Fix(value) End If Return 0 End Get End Property End Class 'MyModel End Class