gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 08:52:12 25 4
gpt4 key购买 nike

在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com