EventToCommandBehavior

EventToCommandBehavior

本文介绍了EventHandlerBehavior 与 EventToCommandBehavior的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Xamarin Forms 中,EventHandlerBehavior 和 EventToCommandBehavior 之间有什么区别?我一直在成功使用前者,但有人建议我改用后者.EventToCommandBehavior 不那么冗长,这是一件好事.

In Xamarin Forms what is the difference between the EventHandlerBehavior and EventToCommandBehavior? I have been using the former successfully, but the latter was suggested to me to use instead. EventToCommandBehavior is less verbose which is a good thing.

推荐答案

关于EventHandlerBehavior和EventToCommandBehavior的区别,我有几点,大家可以看看:

About difference between EventHandlerBehavior and EventToCommandBehavior, I have some point, you can take a look:

对于EventHandlerBehavior,您需要首先在您的项目中安装Behaviors.Forms,行为让您可以向控件添加功能,而无需对它们进行子类化.相反,功能是在行为类中实现的,并附加到控件上,就好像它是控件本身的一部分一样.行为使您能够实现通常必须作为代码隐藏编写的代码,因为它直接与控件的 API 交互,从而可以简洁地附加到控件并打包以在多个应用程序中重用.

For EventHandlerBehavior, you need to install Behaviors.Forms in your project firstly, behaviors let you add functionality to controls without having to subclass them. Instead, the functionality is implemented in a behavior class and attached to the control as if it was part of the control itself. Behaviors enable you to implement code that you would normally have to write as code-behind, because it directly interacts with the API of the control in such a way that it can be concisely attached to the control and packaged for reuse across more than one app.

对于EventToCommandBehavior,EventToCommandBehavior是一个自定义类,需要先创建从BehaviorBase类派生的EventToCommandBehavior类,然后实现Bindable Properties,详细信息可以看:https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/behaviors/reusable/event-to-command-behavior

For EventToCommandBehavior,the EventToCommandBehavior is a custom class, there are need you create EventToCommandBehavior class derives from the BehaviorBase class firstly, then implementing Bindable Properties, for detailed info, you can take a look:https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/behaviors/reusable/event-to-command-behavior

所以我建议你可以使用EventHandlerBehavior,因为你不需要在后面创建很多代码.

So I suggest you can use EventHandlerBehavior, because you don't need to create many code behind.

来自 community-toolkit 的 EventHandlerBehavior 现在等同于 EventHandlerBehavior.

EventHandlerBehavior from community-toolkit is now equivalent to EventHandlerBehavior.

文档:https://docs.microsoft.com/en-us/xamarin/community-toolkit/behaviors/eventtocommandbehavior

这篇关于EventHandlerBehavior 与 EventToCommandBehavior的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 07:12