在 Xamarin Forms MVVM 项目中,我都见过:
public ICommand MyCommand {...}
和
公共(public)命令 MyCommand {...}
这两者有什么区别,什么时候应该用哪个?我可以用 Command
替换所有 ICommand
而不会产生不良影响吗?
最佳答案
What is the difference between the two, and when should I use which?
它们基本上都提供相同的功能。第一个 ICommand
允许接口(interface)的更多自定义实现,而第二个定义包装 Action
的 ICommand
实现。它强制实现至少具有 Command
的基础,并且如果您不想滚动自己的 ICommand
实现,它还提供了一个起点。
Could I replace all
ICommand
's withCommand
's with no ill effect?
一旦你使用的东西继承自 ICommand
,框架就会很开心。
ICommand command = new Command (() => Debug.WriteLine ("Command executed"));
var button = new Button {
Text = "Hit me to execute the command",
Command = command,
};
关于mvvm - Xamarin Forms - ICommand 和 Command 之间的区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38648145/