0. MVVM介绍及前置知识
上图来自维基。组成要素:
- Model:表示具体数据内容(represents real state content)
- View:界面展示
- View Model:View的抽象,提供公共属性和命令(an abstraction of the view exposing public properties and commands),业务代码
- Binder:(a view directly binds to properties on the view model to send and receive updates.)
界面交互方式:
- 通过 RoutedEvents 响应
- 通过命令Command(Commands provides glue between View and ViewModel for interactivity)
1. 初始工作
首先建立三个文件夹,用以存放Command、ViewModel和View
2. 创建view
在MainWindow.xaml中添加如下代码