Here, we will discuss the following three triggers used in XAML.
- Property Trigger
- Data Trigger
- Multi Trigger
Property Trigger
Property trigger is a trigger that gets fired when a property of a specific element is set to a specific value.
Let’s go through its syntax and example.
XAML
- <Entry Placeholder="Enter Email">
- <Entry.Triggers>
- <Trigger TargetType="Entry" Property="IsFocused" Value="True">
- <Setter Property="BackgroundColor" Value="Black"/>
- <Setter Property="TextColor" Value="White"/>
- </Trigger>
- </Entry.Triggers>
- </Entry>
Explanation
In this example, we made a trigger which gets fired when our entry gets focused. And after the trigger fires, it sets the background color and text color of the element. This is one of the simple examples of property trigger.
Main things to remember in this trigger are,
- Target Type
It is the control name to which we are going to use the trigger.
- Property
This is the property of the control that is monitored.
- Value
It is the value which fires the trigger when a monitored property is set to a specific value.
- Setter
Collection of setters are applied to control when a specified condition is met.
Output
The output shows two images. In the first image, our entry is not focused and in the second image, the entry is focused; this activates our trigger and the conditions are applied to it.

Data Trigger
Data trigger is based on the binding that comes from any property of element present in this page or a ViewModel of a page. It is similar to property trigger but property trigger is only specified to a single element and does not depend upon binding values from other elements.
Let’s go through its syntax and example.
XAML
- <Entry Placeholder="Enter Email" Text="" x:Name="Email">
- <Entry.Triggers>
- <Trigger TargetType="Entry" Property="IsFocused" Value="True">
- <Setter Property="BackgroundColor" Value="Black"/>
- <Setter Property="TextColor" Value="White"/>
- </Trigger>
- </Entry.Triggers>
- </Entry>
- <Button Text="Submit">
- <Button.Triggers>
- <DataTrigger TargetType="Button" Binding="{Binding Source={x:Reference Email}, Path=Text.Length}" Value="0">
- <Setter Property="IsEnabled" Value="False"/>
- <Setter Property="BackgroundColor" Value="Red"/>
- </DataTrigger>
- </Button.Triggers>
- </Button>



Join the conversation! Your thoughts help the community grow.