Xamarin.Forms Guides | Samples

Xamarin.Forms.DataTrigger Class

Class that represents a condition on an arbitrary binding, along with a list of Setter objects that will be applied when the condition is met.

See Also: DataTrigger


public sealed class DataTrigger : TriggerBase, IValueProvider


The DataTrigger class is suitable for checking values on other controls, as well as any property on the control to which it has been added. That is, its default binding context is the control to which it has been added.

The XML example below prompts the user to type in the secret, which is, "The text color is green". When the user has typed "The", the Entry text changes color to red. When the user completes the secret, the Label text turns green. The code is turned back to the default color if the user then edits the secret. This example shows how to bind to the enclosing control (Entry from Entry), and to an arbitary control (Entry from Label)

XML Example

              <?xml version="1.0" encoding="utf-8"?>
              <ContentPage    xmlns="http://xamarin.com/schemas/2014/forms"
                  <StackLayout VerticalOptions="Center">
                      <Label Text="Can you tell me the secret?" VerticalOptions="Center" HorizontalOptions="Center">
                              <DataTrigger TargetType="Label"
                                  Binding="{Binding Source={x:Reference checkEntry},
                                  Value="The text color is green">
                                  <Setter Property="TextColor" Value="Color.Green" />
                      <Entry Placeholder="Type the secret here." x:Name="checkEntry" VerticalOptions="Center" HorizontalOptions="Center">
                              <DataTrigger TargetType="Entry"
                                  Binding="{Binding Text}"
                                  <Setter Property="TextColor" Value="Red" />


Namespace: Xamarin.Forms
Assembly: Xamarin.Forms.Core (in Xamarin.Forms.Core.dll)
Assembly Versions:,,,

The members of Xamarin.Forms.DataTrigger are listed below.

See Also: TriggerBase

Public Constructors

Initializes a new DataTrigger instance.

Public Properties

BindingBindingBase. Gets or sets the binding whose value will be compared to DataTrigger.Value to determine when to invoke the setters.
SettersIList<Setter>. Gets the list of Setter objects that will be applied when the binding that is named by the DataTrigger.Binding property becomes equal to DataTrigger.Value.
ValueObject. Gets or sets the value of the binding, named by the DataTrigger.Binding property, that will cause the setters to be applied.

Explicitly Implemented Interface Members

DataTrigger$IValueProvider.ProvideValue(IServiceProvider)For internal use by the XAML infrastructure.