Hi Steve,
The objects assigned to the Tag property need to comply with the following requiresments in order to operate with history and be serialized for drag/drop, clipboard and preview purposes. These requiresments are:
1. Default constructor
2. Implement ICloneable
3. Be marked as serializable
Following is a sample code that demonstrates a custom Tag object:
private void Form1_Load(object sender, EventArgs e)
{
// create a dummy document, shape and tag
NDrawingDocument doc = new NDrawingDocument();
NShape shape = new NRectangleShape();
doc.ActiveLayer.AddChild(shape);
MyTag t1 = new MyTag();
t1.BoolValue = false;
shape.Tag = t1;
// start a transaction
doc.StartTransaction("My Transaction");
// modify the tag
MyTag t2 = new MyTag();
t2.BoolValue = true;
shape.Tag = t2;
// commit the transaction
doc.Commit();
// at this point the value of the tag is t2, so BoolValue is true
Debug.Assert(((MyTag)shape.Tag).BoolValue == true);
// perform an undo
doc.HistoryService.Undo();
// at this point the history applied a clone of t1, so the value of BoolValue is false
Debug.Assert(((MyTag)shape.Tag).BoolValue == false);
}
///
/// Must implement ICloneable and be marked as [Serializable]
/// [Serializable]
public class MyTag : ICloneable
{
///
/// Must have a default contructor
/// public MyTag()
{
BoolValue = false;
}
///
/// Must implement ICloneable
/// ///
public object Clone()
{
MyTag clone = new MyTag();
clone.BoolValue = this.BoolValue;
return clone;
}
public bool BoolValue;
}
Best Regards,
Nevron Support Team