【发布时间】:2016-10-11 21:24:08
【问题描述】:
我有一个问题,我看了很多关于 MVVM 的教程,但我仍然感到困惑。 我有一个带有多个按钮的界面,我必须实现 ICommand 界面才能将命令绑定到视图。
我是这样做的:
主要解决方案
Main Solution
Model
SomeClass.cs
ViewModel
Commands
SomeCommands.cs
SomeViewModel.cs
好的,现在在界面中我有多个按钮,每个按钮都做不同的事情,例如,一个用于启动线程,另一个用于取消它,第三个用于另一件事。 我应该为视图上的每个按钮创建一个实现 ICommand 接口的单独类吗?
Main Solution
Model
SomeClass.cs
ViewModel
Commands
StartCommands.cs
CancelCommands.cs
OtherCommands.cs
SomeViewModel.cs
我问这个是因为当我实现 ICommand 接口时,我只有一个“Execute”方法和一个“CanExecute”方法。在一个View上通过绑定实现多个按钮的常用方法是什么?
我在网上搜索了一个例子,但没有任何运气......其中很多都很令人困惑,而且肯定不适合像我这样的新手。
另一件事是当我有多个视图和多个视图模型时,我应该创建多个命令文件夹来嵌套它吗?
Main Solution
Model
SomeClass.cs
ViewModel
FirstCommands
StartCommands.cs
CancelCommands.cs
OtherCommands.cs
SecondCommands
StartCommands.cs
CancelCommands.cs
OtherCommands.cs
FirstViewModel.cs
SecondViewModel.cs
【问题讨论】: