TriggerAction<T> Class

Definition

A generic base class for user-defined actions that are performed when a trigger condition is met.

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

Type Parameters

T

The type on which Invoke(T) acts.

Inheritance
TriggerAction<T>

Remarks

The example below shows how developers can use a trigger to respond to events and update the value of a control property by using TriggerAction<T> classes. The example prompts the user to answer a question about the color of the text, and then calls ColorTriggerAction to turn the text red when the user types "The text color is red". Developers should note that, while this example does not change the text back to the default color when the user continues to edit the string, the developer could additionally implement and specify an exit action to obtain that result.

With the ColorTriggerAction class below defined in the TriggerDemo namespace:

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

the developer can use the XAML below to create the page that responds to the secret string by changing the color of the Entry text area to red.

<?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>

Constructors

TriggerAction<T>()

Creates a new instance of the TriggerAction<T> class.

Properties

AssociatedType

Gets the type of the objects with which this TriggerAction can be associated.

(Inherited from TriggerAction)

Methods

Invoke(Object)

Application developers override this method to provide the action that is performed when the trigger condition is met.

Invoke(T)

Application developers override this method to provide the action that is performed when the trigger condition is met.

Applies to

See also