EventTrigger 类

定义

表示触发事件以及在引发事件时将调用的 TriggerAction 对象列表的类。

public ref class EventTrigger sealed : Microsoft::Maui::Controls::TriggerBase
[Microsoft.Maui.Controls.ContentProperty("Actions")]
public sealed class EventTrigger : Microsoft.Maui.Controls.TriggerBase
[<Microsoft.Maui.Controls.ContentProperty("Actions")>]
type EventTrigger = class
    inherit TriggerBase
Public NotInheritable Class EventTrigger
Inherits TriggerBase
继承
属性

注解

以下示例演示了开发人员如何使用事件触发器来响应事件并更新控件属性的值。

ColorTriggerAction 命名空间中 TriggerDemo 定义了以下类:

public class ColorTriggerAction : TriggerAction<Entry>
{
  protected override void Invoke(Entry sender)
  {
      Color[] color ={ Color.Red,
                       Color.Orange,
                       Color.Yellow,
                       Color.Green,
                       Color.Blue,
                       Color.Indigo,
                       Color.Violet };
      sender.TextColor = color[sender.Text.Length % color.Length];
  }
}

开发人员可以使用下面的 XAML 创建一个页面, Entry 该页面在用户输入文本时通过彩虹的颜色循环显示文本区域的颜色。

<?xml version="1.0" encoding="utf-8"?>
<ContentPage    xmlns="http://xamarin.com/schemas/2014/forms"
              xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
              xmlns:local="clr-namespace:TriggerDemo"
              x:Class="TriggerDemo.TriggerDemoPage">
<StackLayout VerticalOptions="Center">
<Label Text="Do you see colors?"
             VerticalOptions="Center"
             HorizontalOptions="Center" />
<Entry Placeholder="Type stuff here."
             VerticalOptions="Center"
             HorizontalOptions="Center"
             BackgroundColor="Black">
<Entry.Triggers>
<EventTrigger Event="TextChanged" >
<local:ColorTriggerAction />
</EventTrigger>
</Entry.Triggers>
</Entry>
</StackLayout>
</ContentPage>

构造函数

EventTrigger()

创建一个新的 EventTrigger 实例。

属性

Actions

获取在引发由 Event 属性标识的事件时将调用的 TriggerAction 对象的列表。

BindingContext

获取或设置一个 对象,该对象包含将由属于此 BindableObject的绑定属性所面向的属性。 这是一种可绑定属性。

(继承自 BindableObject)
Dispatcher

获取创建此可绑定对象时可用的调度程序,否则会尝试查找最接近的可用调度程序 (可能是窗口/应用的) 。

(继承自 BindableObject)
EnterActions

获取将在满足触发条件时调用的 TriggerAction 对象的列表。 忽略 EventTrigger 类。

(继承自 TriggerBase)
Event

获取或设置将导致调用 Actions 中包含的操作的事件名称。

ExitActions

获取在不再满足触发条件时调用的 TriggerAction 对象的列表。 忽略 EventTrigger 类。

(继承自 TriggerBase)
IsSealed

获取一个值,该值指示触发器是否密封。

(继承自 TriggerBase)
TargetType

TriggerBase 对象可附加到的对象类型。

(继承自 TriggerBase)

方法

ApplyBindings()

将所有当前绑定应用于 BindingContext

(继承自 BindableObject)
ClearValue(BindableProperty)

清除以前为可绑定属性设置的任何值。

(继承自 BindableObject)
ClearValue(BindablePropertyKey)

清除以前为其键标识的可绑定属性设置的任何值。

(继承自 BindableObject)
CoerceValue(BindableProperty)

强制指定可绑定属性的值。 这是通过调用 BindableProperty.CoerceValueDelegate 指定的可绑定属性来完成的。

(继承自 BindableObject)
CoerceValue(BindablePropertyKey)

强制指定可绑定属性的值。 这是通过调用 BindableProperty.CoerceValueDelegate 指定的可绑定属性来完成的。

(继承自 BindableObject)
GetValue(BindableProperty)

返回给定的可绑定属性中包含的值。

(继承自 BindableObject)
IsSet(BindableProperty)

确定是否存在可绑定属性以及是否设置了值。

(继承自 BindableObject)
OnBindingContextChanged()

引发 BindingContextChanged 事件。

(继承自 BindableObject)
OnPropertyChanged(String)

引发 PropertyChanged 事件。

(继承自 BindableObject)
OnPropertyChanging(String)

引发 PropertyChanging 事件。

(继承自 BindableObject)
RemoveBinding(BindableProperty)

从可绑定属性中删除以前设置的绑定。

(继承自 BindableObject)
SetBinding(BindableProperty, BindingBase)

将绑定分配给可绑定属性。

(继承自 BindableObject)
SetValue(BindableProperty, Object)

设置指定的可绑定属性的值。

(继承自 BindableObject)
SetValue(BindablePropertyKey, Object)

设置指定的可绑定属性的值。

(继承自 BindableObject)
UnapplyBindings()

从当前上下文中删除所有当前绑定。

(继承自 BindableObject)

事件

BindingContextChanged

BindingContext 属性的值更改时发生。

(继承自 BindableObject)
PropertyChanged

在属性值更改时发生。

(继承自 BindableObject)
PropertyChanging

在属性值更改时发生。

(继承自 BindableObject)

显式接口实现

IDynamicResourceHandler.SetDynamicResource(BindableProperty, String)

表示触发事件以及在引发事件时将调用的 TriggerAction 对象列表的类。

(继承自 BindableObject)

扩展方法

GetPropertyIfSet<T>(BindableObject, BindableProperty, T)

表示触发事件以及在引发事件时将调用的 TriggerAction 对象列表的类。

SetAppTheme<T>(BindableObject, BindableProperty, T, T)

表示触发事件以及在引发事件时将调用的 TriggerAction 对象列表的类。

SetAppThemeColor(BindableObject, BindableProperty, Color, Color)

表示触发事件以及在引发事件时将调用的 TriggerAction 对象列表的类。

SetBinding(BindableObject, BindableProperty, String, BindingMode, IValueConverter, String)

创建绑定并将其应用到属性。

适用于

另请参阅