Search
DiagramBase.SerializeTag Event
See Also
 





Raised when the Tag or Id of a diagram item must be serialized into an XML document.

Namespace: MindFusion.Diagramming.Wpf
Assembly: MindFusion.Diagramming.Wpf

 Syntax

C#  Copy Code

public event EventHandler<SerializeTagEventArgs> SerializeTag

Visual Basic  Copy Code

Public Event SerializeTag As EventHandler(Of SerializeTagEventArgs)

 Event Data

SerializeTag 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 serialized. This object can be either a diagram item, group, cell or anchor point.

Tag

The Tag object being serialized.

Representation

An XmlElement instance where the XML representation of the Tag should be saved.

Context

An XmlPersistContext object providing information about the document being serialized, along with methods that help you serialize data to XML.

Handled

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

 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 DeserializeTag.

 Example

C#  Copy Code

private void Write(string fileName)
{
    diagram.SerializeTag += new SerializeTagEventHandler(SerializeTag);
    diagram.SaveToXml(fileName);
}

void SerializeTag(object sender, SerializeTagEventArgs e)
{
    e.Handled = true;
    object tag = e.Tag;
    string stringRepresentation = "";

    if (tag != null)
    {
        stringRepresentation = tag.GetType().ToString();
        stringRepresentation += ";";
        stringRepresentation += tag.ToString();
    }

    XmlNode repNode =
        e.Context.XmlDocument.CreateTextNode(stringRepresentation);
    e.Representation.AppendChild(repNode);
}

Visual Basic  Copy Code

Private Sub Write(ByVal fileName As String)

    AddHandler diagram.SerializeTag, New SerializeTagEventHandler(AddressOf SerializeTag)
    diagram.SaveToXml(fileName)

End Sub

Sub SerializeTag(ByVal sender As Object, ByVal e As SerializeTagEventArgs)

    e.Handled = True

    Dim tag As Object = e.Tag
    Dim stringRepresentation As String = ""

    If Not Tag Is Nothing Then

        stringRepresentation = Tag.GetType().ToString()
        stringRepresentation += ";"
        stringRepresentation += Tag.ToString()

    End If

    Dim repNode As XmlNode = _
        e.Context.XmlDocument.CreateTextNode(stringRepresentation)
    e.Representation.AppendChild(repNode)

End Sub

 See Also