Northwoods.GoWeb Assembly > Northwoods.GoWeb Namespace > GoObject Class : ChangeValue Method |
'Declaration Public Overridable Sub ChangeValue( _ ByVal e As GoChangedEventArgs, _ ByVal undo As Boolean _ )
public virtual void ChangeValue( GoChangedEventArgs e, bool undo )
If you override this method, be sure to call the base method for all GoChangedEventArgs.SubHint values that your override method 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 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 object. You should check this property before making "unrelated" side-effects.
public bool Orthogonal { get { return myOrthogonal; } set { // only set the value and do other things if the value has changed bool old = myOrthogonal; if (old != value) { myOrthogonal = value; // maybe clear out some internal cached state too ResetStuff(); // notify about the change Changed(ChangedOrthogonal, 0, old, NullRect, 0, value, NullRect); // when set to true, and when not undoing/redoing, recalculate the stroke if (value && !this.Initializing) { ClearPoints(); CalculateRoute(); } } } } public override void ChangeValue(GoChangedEventArgs e, bool undo) { switch (e.SubHint) { case ChangedOrthogonal: { this.Orthogonal = (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