新的wpf和MVVM。我有點困惑什麼屬於什麼。viewModel vs model負責與業務層進行通信?
讓我們假設我們有一個btnSave的視圖。
保存誰負責調用業務層?
我的理解是,模型只是持有型物業,並沒有方法 視圖模型實際上是實現EG「DelegateCommand SaveCommand,因此調用業務層。 不過,我已被告知,實際上是模型調用業務層的責任。
例如從約什 - 史密斯採取MSDN從
提取物有
public ICommand SaveCommand
{
get
{
if (_saveCommand == null)
{
_saveCommand = new RelayCommand(param => Save(),param => CanSave);
}
return _saveCommand;
}
}
/// <summary>
/// Saves the customer to the repository. This method is invoked by the SaveCommand.
/// </summary>
private void Save()
{
if (!_customer.IsValid)
throw new InvalidOperationException(Strings.CustomerViewModel_Exception_CannotSave);
if (this.IsNewCustomer)
_customerRepository.AddCustomer(_customer);
base.OnPropertyChanged("DisplayName");
}
你的意見很睦h讚賞。
嗨, 所以你說我在想什麼,但上面的ElectricDialect和Reed Coopsey認爲是相反的。 我是wpf的新手,感到困惑! – user9969
嗨。是的,這個術語可能會讓人困惑。引用的文章有助於解決這個問題--mvvm是Model-View-Presenter的擴展,它是Model-View-Controller的變體。該模型是數據。這在MVVM,MVP,MVC中是一致的。視圖儘可能愚蠢。這又是一致的。 Controller是MVC的核心。它將觀點與模型聯繫在一起。控制器在用戶與視圖交互時接收消息。在MVP模式中,Presenter類似於Controller。在MVVM中,與MVP不同,ViewModel不需要對視圖的引用。 – soulia