本文介绍了行为和事件触发器之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Xamarin.Forms中,您具有行为在某些事件上执行某些动作.例如,检查在文本更改事件中输入是否有效.

In Xamarin.Forms you have Behaviors that perform certain actions on certain events. For example checking if input is valid on a text change event.

今天早上,我开始阅读 Triggers ,则有一种特定类型的触发器称为事件触发器几乎与行为相同.甚至样本也执行相同的操作.

This morning I started reading up on Triggers, there is a certain type of trigger called the Event Trigger that pretty much does the same thing as a Behavior. Even the sample performs the same action.

double result;
bool isValid = Double.TryParse (entry.Text, out result);
entry.TextColor = isValid ? Color.Default : Color.Red;

所以我的问题是:行为和事件触发器之间有什么区别?

推荐答案

触发器是包含一个或多个动作并响应某些刺激而调用这些动作的对象.一种非常常见的触发器是为响应事件而触发的触发器(EventTrigger).其他示例可能包括在计时器上触发的触发器,或在引发未处理的异常时触发的触发器.

Triggers are objects that contain one or more actions and invoke those actions in response to some stimulus. One very common trigger is one that fires in response to an event (an EventTrigger). Other examples might include a trigger that fires on a timer, or a trigger that fires when an unhandled exception is thrown.

行为没有调用的概念;相反,它更多地充当对象的附加组件:如果需要,可以将附加功能附加到对象.它可能会响应来自环境的刺激而做某些事情,但是不能保证用户可以控制这种刺激是什么:行为作者可以决定哪些可以自定义,哪些不能自定义.

A behavior does not have the concept of invocation; instead, it acts more as an add-on to an object: optional functionality that can be attached to an object if desired. It may do certain things in response to stimulus from the environment, but there is no guarantee that the user can control what this stimulus is: it is up to the behavior author to determine what can and cannot be customized.

有关更多信息,

查看此

参见此

这篇关于行为和事件触发器之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 20:55