无法使用集合初始值初始化类型,原因是它未实现“System.Collections.IEnumerable”
public class BookViewModel:INotifyPropertyChanged
{
//定义书类的集合
private ObservableCollection<BookModel> bookModel;
//将集合作为ViewModel层的属性
public ObservableCollection<BookModel> Book
{
get
{
if (bookModel == null)
{
bookModel = new ObservableCollection<BookModel>();
}
return bookModel;
}
set
{
if (bookModel != value)
{
bookModel = value;
NotifyPropertyChanged("AllFruit");
}
}
}
//定义属性改变事件
public event PropertyChangedEventHandler PropertyChanged;
//实现属性改变事件
private void NotifyPropertyChanged(string p)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(p));
}
}
public void getBook()
{
ServiceReference1.Service1SoapClient s = new ServiceReference1.Service1SoapClient();
s.getBooksCompleted += new EventHandler<ServiceReference1.getBooksCompletedEventArgs>(s_getBooksCompleted);
s.getBooksAsync();
}
void s_getBooksCompleted(object sender, ServiceReference1.getBooksCompletedEventArgs e)
{
if (e.Error == null)
{
foreach (var i in e.Result)
{
Book.Add(new BookModel() { i.BookID, i.BookName, i.Author, i.Price });//错误地方
}
}
}
}
怎么实现IEnumerable这个接口?
[解决办法]
自顶一个
[解决办法]
问题解决了
[解决办法]
实现IEnumerable的方法就行了Getnumerator()