撤消/重做集合中的收藏 [英] Undo/Redo in collection of collection
问题描述
我需要在我的winform项目中实现撤消功能.
我实现了一个将属性值和属性名称存储为对象的堆栈.
当我需要撤消操作时,我只是从堆栈中弹出并重新分配值.现在的问题是它可以与字符串属性一起正常工作,但不能与集合一起工作.即我有一个类,即类x,它包含一些属性,即字符串ID等,以及一些其他集合,即List< y> ,列表< z>并且这些集合类也具有一些集合,即Y类具有"List<a>
"等
i need to implement undo function in my winform project.
i have implemented a stack which store property value and property name as object.
when i need to undo i just pop from stack and reassign the value. now the problem is its working fine with string property, but not with collection. i.e. i have a class i.e. class x, which contain some property i.e. String ID etc and some other collection i.e. List<y> , List<z> and these collection classes also have some collection i.e. Class Y have "List<a>
" etc
class X : inotify
{
string id;
YCollection YCol;
ZCollection ZCol;
}
YCollection : List<y>
{
Add(Y)
{
---
}
Remove(Y)
{
}
}
Class Y: inotify
{
string ID;
ACollection ACol;
}
Class ACollection : List<a>
{
Add(A)
Remove(A)
}
class A : inotify
{
string ID;
}
现在我不知道该如何解决这个问题,因为当较低级别的更改(即A类对象)发生时,我不知道如何查找更改的发生位置以及何时将该更改推入堆栈以进行撤消.
有人可以帮忙吗.
now i dont know how to tackle this problem, because when change occure in lower level i.e. Class A object, i dont know how to find where change occure, and when to push this into stack for undo.
can someone help.
推荐答案
你好
使用ObservableCollection
代替List
例如:
Hello
UseObservableCollection
instead ofList
For example:
private ObservableCollection<MyClass> _myProperty;
public ObservableCollection<MyClass> MyProperty
{
get { return _myProperty; }
set
{
_myProperty = value;
_myProperty.CollectionChanged += new NotifyCollectionChangedEventHandler((object sender, NotifyCollectionChangedEventArgs e) => {
//Some Code
}
}
http://msdn.microsoft.com/en-us/library/ms668604.aspx [ ^ ]
http://msdn.microsoft.com/en-us/library/ms653375.aspx [ ^ ]
http://msdn.microsoft.com/en-us/library/ms668604.aspx[^]
http://msdn.microsoft.com/en-us/library/ms653375.aspx[^]
这篇关于撤消/重做集合中的收藏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!