Note
Access to this page requires authorization. You can try signing in or .
Access to this page requires authorization. You can try .
EventTrigger Class
Definition
- Namespace:
- Microsoft.Maui.Controls
- Assembly:
- Microsoft.Maui.Controls.dll
- Source:
- EventTrigger.cs
- Source:
- EventTrigger.cs
- Source:
- EventTrigger.cs
- Source:
- EventTrigger.cs
Important
Some information relates to prerelease product that may be substantially modified before itβs released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
A trigger that fires actions in response to a specified event on the associated element.
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
- Inheritance
- Attributes
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:
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.
<?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>
Constructors
| Name | Description |
|---|---|
| EventTrigger() |
Initializes a new EventTrigger instance. |
Properties
| Name | Description |
|---|---|
| Actions |
Gets the collection of TriggerAction objects to invoke when the event fires. |
| BindingContext |
Gets or sets an object that contains the properties that will be targeted by the bound properties that belong to this BindableObject. This is a bindable property. (Inherited from BindableObject) |
| Dispatcher |
Gets the dispatcher that was available when this bindable object was created, otherwise tries to find the nearest available dispatcher (probably the window's/app's). (Inherited from BindableObject) |
| EnterActions |
Gets the collection of TriggerAction objects to invoke when the trigger condition becomes true. (Inherited from TriggerBase) |
| Event |
Gets or sets the name of the event that triggers the actions. |
| ExitActions |
Gets the collection of TriggerAction objects to invoke when the trigger condition becomes false. (Inherited from TriggerBase) |
| IsSealed |
Gets a value indicating whether this trigger has been attached to an element and can no longer be modified. (Inherited from TriggerBase) |
| TargetType |
Gets the type of object to which this trigger can be attached. (Inherited from TriggerBase) |
Methods
| Name | Description |
|---|---|
| ApplyBindings() |
Applies all the current bindings to BindingContext. (Inherited from BindableObject) |
| ClearValue(BindableProperty) |
Clears any value that is previously set for a bindable property. (Inherited from BindableObject) |
| ClearValue(BindablePropertyKey) |
Clears any value that is previously set for a bindable property, identified by its key. (Inherited from BindableObject) |
| CoerceValue(BindableProperty) |
Coerces the value of the specified bindable property. This is done by invoking BindableProperty.CoerceValueDelegate of the specified bindable property. (Inherited from BindableObject) |
| CoerceValue(BindablePropertyKey) |
Coerces the value of the specified bindable property. This is done by invoking BindableProperty.CoerceValueDelegate of the specified bindable property. (Inherited from BindableObject) |
| GetValue(BindableProperty) |
Returns the value that is contained in the given bindable property. (Inherited from BindableObject) |
| IsSet(BindableProperty) |
Determines whether or not a bindable property exists and has a value set. (Inherited from BindableObject) |
| OnBindingContextChanged() |
Raises the BindingContextChanged event. (Inherited from BindableObject) |
| OnPropertyChanged(String) |
Raises the PropertyChanged event. (Inherited from BindableObject) |
| OnPropertyChanging(String) |
Raises the PropertyChanging event. (Inherited from BindableObject) |
| RemoveBinding(BindableProperty) |
Removes a previously set binding from a bindable property. (Inherited from BindableObject) |
| SetBinding(BindableProperty, BindingBase) |
Assigns a binding to a bindable property. (Inherited from BindableObject) |
| SetValue(BindableProperty, Object) |
Sets the value of the specified bindable property. (Inherited from BindableObject) |
| SetValue(BindablePropertyKey, Object) |
Sets the value of the specified bindable property. (Inherited from BindableObject) |
| UnapplyBindings() |
Removes all current bindings from the current context. (Inherited from BindableObject) |
Events
| Name | Description |
|---|---|
| BindingContextChanged |
Occurs when the value of the BindingContext property changes. (Inherited from BindableObject) |
| PropertyChanged |
Occurs when a property value changes. (Inherited from BindableObject) |
| PropertyChanging |
Occurs when a property value is changing. (Inherited from BindableObject) |
Explicit Interface Implementations
| Name | Description |
|---|---|
| IDynamicResourceHandler.SetDynamicResource(BindableProperty, String) | (Inherited from BindableObject) |
Extension Methods
| Name | Description |
|---|---|
| GetPropertyIfSet<T>(BindableObject, BindableProperty, T) | |
| SetAppTheme<T>(BindableObject, BindableProperty, T, T) | |
| SetAppThemeColor(BindableObject, BindableProperty, Color, Color) | |
| SetBinding(BindableObject, BindableProperty, String, BindingMode, IValueConverter, String) |
Creates and applies a binding to a property. |
| SetBinding<TSource,TProperty>(BindableObject, BindableProperty, Func<TSource,TProperty>, BindingMode, IValueConverter, Object, String, Object, Object, Object) |
Creates a binding between a property on the source object and a property on the target object. |
Applies to
See also
Feedback
Was this page helpful?
