Search⌘ K

Property Triggers

Explore how to implement property triggers in .NET MAUI to create dynamic user interfaces. Understand setting triggers on specific elements and globally, and learn how property changes like focus can alter element properties such as text color.

Property triggers in .NET MAUI trigger some sort of action when a property on a specific page element is set to a specific value. There are multiple ways of defining property triggers. We'll look at them in the following project setup:

<?xml version = "1.0" encoding = "UTF-8" ?>
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:PropertyTriggersDemo"
             x:Class="PropertyTriggersDemo.App">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Resources/Styles/Colors.xaml" />
                <ResourceDictionary Source="Resources/Styles/Styles.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>
.NET MAUI project example with property triggers demonstration

Adding property triggers

First, we'll look at how to add a property trigger to a specific element. We have an example of it on lines 37–47 on the MainPage.xaml file, where we're adding a property trigger to a specific Entry element.

Any trigger, including property triggers, is set inside a <{element type}.Triggers> block. So, since we're ...