Xamarin Forms - ICommand 和 Command 之间的区别?
Xamarin Forms - Difference Between ICommand and Command?
在 Xamarin Forms MVVM 项目中,我都见过:
public ICommand MyCommand {...}
和
public Command MyCommand {...}
两者有什么区别,什么时候应该使用哪个?我可以将所有 ICommand
替换为 Command
而没有不良影响吗?
What is the difference between the two, and when should I use which?
它们基本上都提供相同的功能。第一个 ICommand
允许接口的更多自定义实现,而第二个定义 ICommand
包装 Action
的实现。它强制实现至少具有 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,
};
在 Xamarin Forms MVVM 项目中,我都见过:
public ICommand MyCommand {...}
和
public Command MyCommand {...}
两者有什么区别,什么时候应该使用哪个?我可以将所有 ICommand
替换为 Command
而没有不良影响吗?
What is the difference between the two, and when should I use which?
它们基本上都提供相同的功能。第一个 ICommand
允许接口的更多自定义实现,而第二个定义 ICommand
包装 Action
的实现。它强制实现至少具有 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,
};