public static void Track(string name, Action undo) { var acc = new SingleItemAccumulator(name, undo); acc.ClosedForBusiness = true; AccumulatorManager.Instance.Add(acc, ScopeState.Do); }
/// <summary> /// Called right before the PropertyChanged event is fired. Return false to block the change /// </summary> /// <param name="name"></param> /// <param name="currentValue">value before the change</param> /// <param name="raiseEvent">whether or not the PropertyChanged event will actually be raised</param> protected virtual bool OnPropertyChanging(string name, object currentValue, bool raiseEvent, object newValue) { if (TrackChanges && Globals.ScopeEachChange && Accumulator == null) { SingleItemAccumulator.Track($"{name} changed to {newValue}", () => Set(currentValue, name, raiseEvent)); } else if (TrackChanges) { Accumulator?.AddUndo(() => Set(currentValue, name, raiseEvent)); } return(true); }