TriggerAction<T> 類別

定義

符合觸發條件時所執行使用者定義動作的泛型基底類別。

public abstract class TriggerAction<T> : Xamarin.Forms.TriggerAction where T : BindableObject
type TriggerAction<'T (requires 'T :> BindableObject)> = class
    inherit TriggerAction

類型參數

T

作用所在的 Invoke(T) 型別。

繼承
TriggerAction<T>

備註

下列範例顯示開發人員如何使用觸發程式來回應事件,以及使用 TriggerAction<T> 類別更新控制項屬性的值。 此範例會提示使用者回答有關文字色彩的問題,然後在使用者輸入「文字色彩為紅色」時,呼叫 ColorTriggerAction 來將文字變成紅色。 開發人員應該注意,雖然此範例不會在使用者繼續編輯字串時將文字變更回預設色彩,但開發人員可以另外實作並指定結束動作來取得該結果。

在 命名空間中 TriggerDemo 定義下列 ColorTriggerAction 類別:

public class ColorTriggerAction : TriggerAction<Entry>
{
    protected override void Invoke(Entry sender)
    {
        sender.TextColor = Color.Red;
    }
}

開發人員可以使用下列 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="What color is &quot;The text&quot;?"
               VerticalOptions="Center"
               HorizontalOptions="Center" />
<Entry Placeholder="Type answer here."
               VerticalOptions="Center"
               HorizontalOptions="Center"
               BackgroundColor="White">
<Entry.Triggers>
<Trigger TargetType="Entry"
                         Property="Text"
                         Value="The text is red" >
<Trigger.EnterActions>
<local:ColorTriggerAction />
</Trigger.EnterActions>
</Trigger>
</Entry.Triggers>
</Entry>
</StackLayout>
</ContentPage>

建構函式

TriggerAction<T>()

建立 TriggerAction<T> 類別的新執行個體。

屬性

AssociatedType

取得可與這個 TriggerAction 建立關聯的物件類型。

(繼承來源 TriggerAction)

方法

Invoke(Object)

應用程式開發人員可以覆寫這個方法,以提供符合觸發條件時所執行的動作。

Invoke(T)

應用程式開發人員可以覆寫這個方法,以提供符合觸發條件時所執行的動作。

適用於

另請參閱