【发布时间】:2011-10-02 05:22:06
【问题描述】:
阅读Josh Smiths article about MVVM 他的视图模型CustomerViewModel 实现INotifyPropertyChanged 但不是底层Customer 类。
在这种情况下,我只能看到一种(可行的)方法来使更改通知起作用 - 仅更改 CustomerViewModel 而不是 Customer。在那种情况下,我的程序的后端逻辑是否也应该简单地针对 ViewModel 工作?这看起来很奇怪,毕竟它们是 View 模型。
谁能解释一下?
谢谢!
澄清:
假设我有一个模型引用和一个引用列表。
public class Quote
{
public string Name { get; set; }
public decimal Value { get; set; }
}
public QuoteViewModel : INotifyPropertyChanged
{
private Quote quote;
public event EventHandler PropertyChanged;
public decimal Value
{
get { return quote.Value; }
set
{
quote.Value = value;
PropertyChanged("Value");
}
}
}
现在,如果 Quote 因后台线程轮询 Web 服务而发生变化,UI 将不会收到通知,因为 Quote 没有实现 INotifyPropertyChanged,除非系统的所有部分都使用 ViewModel?
【问题讨论】: