mvvm - Xamarin Forms - ICommand 和 Command 之间的区别?

标签 mvvm xamarin xamarin.forms icommand

在 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)的更多自定义实现,而第二个定义包装 ActionICommand 实现。它强制实现至少具有 Command 的基础,并且如果您不想滚动自己的 ICommand 实现,它还提供了一个起点。

Could I replace all ICommand's with Command'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/

相关文章:

android - Android 中 MVP 相对于 MVVM 设计模式的缺点

wpf - 在Blend 2013中未打开设计 View

android - 将事件添加到日历中不考虑时间

android - Xamarin.Forms .193 - AppCompat - 全屏 - 无操作栏

android - 推送通知使用负载打开正确的页面

mvvm - 如何从 ViewModel (MVVM Light Toolkit) 访问 View 中的 UserControl (MediaElement)

java - 如何在 Android MVVM 架构中实现对话框选择

elasticsearch - 使用 Xamarin.Forms 与 NEST 的 Guid ID 比较不起作用

ios - 使用 VS for Mac 打包和分发 Xamarin iOS 应用程序

android - 在我的网络上使用 Mac 运行 Xamarin 应用程序时找不到文件 : Error for Contents. json