行为和事件触发器有什么区别?

What is the difference between Behaviors and Event Triggers?

在 Xamarin.Forms 中,您有 Behaviors 对特定事件执行特定操作。例如检查输入在文本更改事件中是否有效。

今天早上我开始阅读 Triggers, there is a certain type of trigger called the Event Trigger,它与行为的作用几乎相同。甚至样本也执行相同的操作。

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

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

Triggers allow us to conditionally make actions within XAML, whereas Behaviors allow to modify and increment the default behavior of any control.


触发器: 触发器是在特定情况后触发的动作。这种情况在 XAML 中用 Trigger 声明定义。每个触发器可以由一个或多个 TriggerActions

行为: 行为旨在扩展您应用它们的视图,远远超出正常使用范围。

Continue reading...


相关文章:

  1. http://www.bravent.net/xamarin-forms-13/
  2. http://www.damirscorner.com/blog/posts/20130624/
  3. http://blogs.msdn.com//an-introduction-to-behaviors-triggers-and-actions.aspx
  4. https://blog.xamarin.com/behaviors-in-xamarin-forms/
  5. https://blog.xamarin.com/triggers-in-xamarin-forms/

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

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

欲了解更多信息,

See This

See This