Xamarin.Forms.EventTrigger Class
Class that represents a triggering event and a list of TriggerAction objects that will be invoked when the event is raised.
See Also: EventTrigger
Syntax
[Xamarin.Forms.ContentProperty("Actions")]
public sealed class EventTrigger : TriggerBase
public sealed class EventTrigger : TriggerBase
See Also
Remarks
The example below shows how developers can use an event trigger to respond to events and update the value of a control property.
With the ColorTriggerAction class below defined in the TriggerDemo namespace:
C# Example
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]; } }
the developer can use the XAML below to create a page that cycles the colors of a Entry text area through the colors of the rainbow as the user enters text.
XAML Example
<?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>
Requirements
Namespace: Xamarin.Forms
Assembly: Xamarin.Forms.Core (in Xamarin.Forms.Core.dll)
Assembly Versions: 0.0.0.0, 1.3.0.0, 1.4.0.0, 1.5.0.0, 2.0.0.0
Assembly: Xamarin.Forms.Core (in Xamarin.Forms.Core.dll)
Assembly Versions: 0.0.0.0, 1.3.0.0, 1.4.0.0, 1.5.0.0, 2.0.0.0
The members of Xamarin.Forms.EventTrigger are listed below.
See Also: TriggerBase
Public Constructors
Creates a new EventTrigger instance. |
Public Properties
[read-only] | Actions | IList<TriggerAction>. Gets the list of TriggerAction objects that will be invoked when the event that is identified by the EventTrigger.Event property is raised. |
Event | String. Gets or sets the name of the event that will cause the actions that are contained in the EventTrigger.Actions to be invoked. |
Protected Methods
override | OnAttached()Internal. | |
override | OnDetaching()Internal. |