Northwoods.GoWeb Assembly > Northwoods.GoWeb Namespace > GoDocument Class : ChangeValue Method |
'Declaration Public Overridable Sub ChangeValue( _ ByVal e As GoChangedEventArgs, _ ByVal undo As Boolean _ )
public virtual void ChangeValue( GoChangedEventArgs e, bool undo )
This handles changes to the document, such as ChangedAllowMove; to the collection of document layers, such as GoLayerCollection.InsertedLayer; and to any document layer, such as GoLayer.InsertedObject. For a GoLayer.ChangedObject event hint, this just calls GoObject.ChangeValue on the GoObject, to handle all the changes for objects such as GoObject.ChangedMovable. This method will raise an ArgumentException
if the argument e's Hint value is not recognized.
If you add a property to a class inheriting from GoDocument, you may want to override this method in order to handle undo/redo. Be sure to call the base method for all Hint values that your override does not handle.
Although properties should be designed so that setting one property does not modify other properties, this is sometimes not practical. Nevertheless it is important to avoid having side-effects when the value is changing due to an undo or redo. One way of doing this is to copy the needed code, but not the auxiliary side-effecting code, from the property setter to the ChangeValue override. Or similarly, you could define a method called from both the setter and the ChangeValue method, parameterized by whether the caller is the setter or not.
But a more convenient way to achieve this is to check the Initializing property that is set to true when the ChangeValue method is being called on this document. You should check this property before making "unrelated" side-effects.
public bool MaintainsPartID { get { return myMaintainsPartID; } set { // only set the value and do other things if the value has changed bool old = myMaintainsPartID; if (old != value) { myMaintainsPartID = value; // notify about the change RaiseChanged(ChangedMaintainsPartID, 0, null, 0, old, NullRect, 0, value, NullRect); // when set to true, and when not undoing/redoing, make sure all parts have unique IDs if (!this.Initializing) { if (value) EnsureUniquePartID(); else ClearPartIDTable(); } } } } public override void ChangeValue(GoChangedEventArgs e, bool undo) { switch (e.SubHint) { case ChangedMaintainsPartID: this.MaintainsPartID = (bool)e.GetValue(undo); return; default: base.ChangeValue(e, undo); return; } }
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2