WPF 引入 Binding、DependencyProperty、Command、Template 等新特性,催生 MVVM(Model-View-ViewModel)架構,乃 MVP(Model-View-Presenter)與 WPF 技術結合演進而來。

關鍵點:引入 IView 介面解耦 UI 與邏輯,支援單元測試與多 UI 實現(Web/WinForm/WPF 共用 Presenter)。

INotifyPropertyChanged核心差異:Presenter 操作 View(介面方法),ViewModel 提供屬性/命令供 View Binding(資料驅動)。
public class FamilyTreeViewModel {
public FamilyTreeViewModel(Person rootPerson) {
_rootPerson = new PersonViewModel(rootPerson);
_firstGeneration = new ReadOnlyCollection<PersonViewModel>(new[] { _rootPerson });
_searchCommand = new SearchFamilyTreeCommand(this); // Command 封裝
}
// 屬性供 View Binding:_rootPerson, _firstGeneration, _searchCommand
}
MVC (系統級) → MVP (頁面級,IView 解耦) → MVVM (WPF Binding/Command 整合, ViewModel 專屬模型)
參考:TreeView with ViewModel、Prism (Composite Application Guidance for WPF)。