我正在尝试对我的应用程序实施撤消和重做。为了实现这些东西 - 我正在使用 Monitored Undo Framework 和 MVVM light。
这是一些代码(没有CanExecute,..)
public class ViewModel_Main : ViewModelBase, ISupportsUndo
{
public ViewModel_Main(IRaDataService dataService)
{
Networks = new ObservableCollection<ViewModel_Network>();
}
private const string NetworksPropertyName = "Networks";
private ObservableCollection<ViewModel_Network> _Networks;
public ObservableCollection<ViewModel_Network> Networks
{
get
{
return _Networks;
}
set
{
_Networks = value;
RaisePropertyChanged(NetworksPropertyName);
}
}
private void AddNetworkCommand_Execute()
{
ViewModel_Network newNetwork = new ViewModel_Network("undefinded.RaNet", "x");
DefaultChangeFactory.Current.OnChanging(this, NetworksPropertyName, Networks, newNetwork);
Networks.Add(newNetwork);
}
private void UndoCommand_Execute()
{
UndoService.Current[this].Undo();
}
public object GetUndoRoot()
{
return this;
}
}
所以让我们来解决我的问题:撤消不起作用..但是为什么呢?
谢谢!