我有一个想要传递给ViewModel.Intuitively的列表,我以为传递给视图模型的构造函数会很简单,但在这样做的时候,我得到的错误是视图模型的构造函数应该是parameterless...This:
public SomeMethod(){
List<T> list = new List<T>();
ViewModel vm = new ViewModel(list);
}视图模型:
public class ViewModel
{
public ObservableCollection<T> Collection { get; set; }
public ViewModel(List<T> t)
{
Collection = new ObservableCollection<T>();
foreach (T item in t)
{
this.Collection.Add(new T (item.value));
}
}我想在ViewModel中创建另一个接受列表作为参数的方法,但是我如何能够从构造函数调用它,因为构造函数也必须将参数传递给它。
发布于 2015-02-19 22:26:30
只需将构造函数保留为空,并将Collection-Property修改为带有支持字段的属性即可。
在这之后,你可以在你的setter中做任何你想做的事情。
private ObservableCollection<T> _collection
public ObservableCollection<T> Collection {
get{
return this._collection;
}
set{
this._collection = value;
// Do what you want here
}https://stackoverflow.com/questions/28608709
复制相似问题