EventTrigger 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
代表觸發事件及引發事件時要叫用之 TriggerAction 物件清單的類別。
[Xamarin.Forms.ContentProperty("Actions")]
public sealed class EventTrigger : Xamarin.Forms.TriggerBase
type EventTrigger = class
inherit 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 |
代表觸發事件及引發事件時要叫用之 TriggerAction 物件清單的類別。 (繼承來源 BindableObject) |
EnterActions |
取得符合觸發條件時要叫用的 TriggerAction 物件清單。 若為 EventTrigger 類別請予以略過。 (繼承來源 TriggerBase) |
Event |
取得或設定事件名稱,這個事件會導致叫用包含在 Actions 中的動作。 |
ExitActions |
取得觸發條件不再符合之後要叫用的 TriggerAction 物件清單。 若為 EventTrigger 類別請予以略過。 (繼承來源 TriggerBase) |
IsSealed |
取得值,指出是否密封觸發程序。 (繼承來源 TriggerBase) |
TargetType |
可附加這個 TriggerBase 物件的目標物件類型。 (繼承來源 TriggerBase) |
方法
事件
BindingContextChanged |
每當 BindingContext 屬性變更時引發。 (繼承來源 BindableObject) |
PropertyChanged |
在屬性變更時引發。 (繼承來源 BindableObject) |
PropertyChanging |
在屬性即將變更時引發。 (繼承來源 BindableObject) |
明確介面實作
IDynamicResourceHandler.SetDynamicResource(BindableProperty, String) |
供 Xamarin.Forms 平台內部使用。 (繼承來源 BindableObject) |
擴充方法
GetPropertyIfSet<T>(BindableObject, BindableProperty, T) |
代表觸發事件及引發事件時要叫用之 TriggerAction 物件清單的類別。 |
SetAppThemeColor(BindableObject, BindableProperty, Color, Color) |
代表觸發事件及引發事件時要叫用之 TriggerAction 物件清單的類別。 |
SetBinding(BindableObject, BindableProperty, String, BindingMode, IValueConverter, String) |
建立並將繫結套用至屬性。 |
SetBinding<TSource>(BindableObject, BindableProperty, Expression<Func<TSource,Object>>, BindingMode, IValueConverter, String) |
已過時。
從運算式建立及套用繫結。 |
SetOnAppTheme<T>(BindableObject, BindableProperty, T, T) |
代表觸發事件及引發事件時要叫用之 TriggerAction 物件清單的類別。 |