public virtual void ChangeValue( GoChangedEventArgs e, bool undo )
Parameters
- e
- The particular GoChangedEventArgs edit.
- undo
- If true, restore the old value, otherwise restore the new value.
public virtual void ChangeValue( GoChangedEventArgs e, bool undo )
If you override this method, be sure to call the base method for all 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; } }