Search
DiagramBase.DeserializeTag Event
See Also
 





Raised when the Tag of a diagram item must be deserialized from XML format.

Namespace: MindFusion.Diagramming
Assembly: MindFusion.Diagramming

 Syntax

C#  Copy Code

public event EventHandler<SerializeTagEventArgs> DeserializeTag

Visual Basic  Copy Code

Public Event DeserializeTag As EventHandler(Of SerializeTagEventArgs)

 Event Data

DeserializeTag event handlers receive an argument of type SerializeTagEventArgs. The following SerializeTagEventArgs members provide information relevant to the event:

Member name

Description

Object

The object whose Tag is being deserialized. This object can be either a diagram item, group, cell or anchor point.

Tag

Set this property to the object that has been deserialized.

Representation

An XmlElement instance that contains the XML representation of a Tag value.

Context

An XmlPersistContext object providing information about the document being deserialized, along with methods that help you deserialize data from XML.

Handled

Set this flag to true if you perform custom tag deserialization.

 Remarks

Only tags of simple value types can be saved and loaded automatically to/from the XML document. You must provide your own serialization for complex types by implementing this event and SerializeTag.

 Example

The following example demonstrates how to deserialize a complex tag value using the DeserializeTag event.

C#  Copy Code

private void Read(string fileName)
{
    diagram.DeserializeTag += new SerializeTagEventHandler(DeserializeTag);
    diagram.LoadFromXml(fileName);
}

private void DeserializeTag(object sender, SerializeTagEventArgs e)
{
    e.Handled = true;
    string type, val;

    XmlText textNode = e.Representation.LastChild as XmlText;
    string stringRep = textNode.Value;
    int pos = stringRep.IndexOf(";");

    if (pos == -1)
        return;

    type = stringRep.Substring(0, pos);
    val = stringRep.Substring(pos + 1);

    Type t = Type.GetType(type);

    object tag = null;
    if (t == typeof(string))
        tag = val;
    else if (t == typeof(int))
        tag = XmlConvert.ToInt32(val);

    e.Tag = tag;
}

Visual Basic  Copy Code

Private Sub Read(ByVal fileName As String)

    AddHandler diagram.DeserializeTag, New SerializeTagEventHandler(AddressOf DeserializeTag)
    diagram.LoadFromXml(fileName)

End Sub

Private Sub DeserializeTag(ByVal sender As Object, ByVal e As SerializeTagEventArgs)

    e.Handled = True

    Dim type As String
    Dim val As String

    Dim textNode As XmlText = CType(e.Representation.LastChild, XmlText)
    Dim stringRep As String = textNode.Value
    Dim pos As Integer = stringRep.IndexOf(";")

    If pos = -1 Then
        Return
    End If

    type = stringRep.Substring(0, pos)
    val = stringRep.Substring(pos + 1)

    Dim t As Type = System.Type.GetType(type)

    Dim tag As Object = Nothing
    If t Is GetType(String) Then
        tag = val
    ElseIf t Is GetType(Integer) Then
        tag = XmlConvert.ToInt32(val)
    End If

    e.Tag = tag

End Sub

 See Also