深入探索MVVM与WinRT组件开发
1. 命令实现与示例
首先,我们来看一个命令实现的示例。以下是 IncreaseAgeCommand 类的实现代码:
void IncreaseAgeCommand::Execute(Object^ parameter) {
auto person = (Person^)parameter;
person->BirthYear++;
}
bool IncreaseAgeCommand::CanExecute(Object^ parameter) {
return true;
}
为了让这个命令起作用,我们可以创建一个命令源,比如按钮,并按以下方式填写命令细节:
<Button Content="Inrease Birth Year With Command"
CommandParameter="{StaticResource p1}">
<Button.Command>
<local:IncreaseAgeCommand />
</Button.Command>
</Button>
通常,在 Command 属性中创建命令并不常见,典型的做法是将其绑定到 ViewModel 上的适当属性。
2. MVVM 模式简介
在处理非简
超级会员免费看
订阅专栏 解锁全文
1254

被折叠的 条评论
为什么被折叠?



