Xamarin.Forms Guides | Samples

Xamarin.Forms.MultiTrigger Class

Class that represents a list of property and binding conditions, and a list of setters that are applied when all of the conditions in the list are met.

See Also: MultiTrigger

Syntax

[Xamarin.Forms.ContentProperty("Setters")]
public sealed class MultiTrigger : TriggerBase

See Also

Remarks

Developers can use a MultiTrigger to compare against property values on the control that contains it by using PropertyTrigger objects, or on any bound property (including those on the enclosing control) by using BindingCondition objects. These can be mixed in the same MultiTrigger.Conditions list.

The XML example below, when added to a Xamarin.Forms app with the correct project namespace, creates a UI that suggests that the user type in a secret and toggle a switch to check if the secret is correct. If the user enters "The text color is green", and toggles the Switch to its On position, then the text that the user typed into the Entry turns green. If either the text is altered to something other than the secret or the Switch is toggled to its Off position, the text returns to the default color

XML 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:PropertyConditionDemo"
             x:Class="PropertyConditionDemo.PropertyConditionDemoPage">
    <StackLayout VerticalOptions="Center">
        <Label Text="Do you know the secret?"
               VerticalOptions="Center"
               HorizontalOptions="Center" />
        <Entry Placeholder="Type the secret!"
               VerticalOptions="Center"
               HorizontalOptions="Center">
            <Entry.Triggers>
                <MultiTrigger TargetType="Entry" >
                    <MultiTrigger.Conditions>
                        <PropertyCondition Property="Text" Value="The text color is green" />
                        <BindingCondition Binding="{Binding Source={x:Reference checkSecret},
                                                            Path=IsToggled}"
                                          Value="true" />
                    </MultiTrigger.Conditions>
                    <Setter Property="TextColor"
                        Value="Color.Green" />
                </MultiTrigger>
            </Entry.Triggers>
        </Entry>
        <Label Text="Check the secret?"
               VerticalOptions="Center"
               HorizontalOptions="Center" />
        <Switch x:Name="checkSecret"
                VerticalOptions="Center"
                HorizontalOptions="Center" />
    </StackLayout>
</ContentPage>

Requirements

Namespace: Xamarin.Forms
Assembly: Xamarin.Forms.Core (in Xamarin.Forms.Core.dll)
Assembly Versions: 1.3.0.0, 1.4.0.0, 1.5.0.0, 2.0.0.0

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

See Also: TriggerBase

Public Constructors

Initializes a new MultiTrigger instance.

Public Properties

[read-only]
ConditionsIList<Condition>. Gets the list of conditions that must be satisfied in ordeer for the setters in the MultiTrigger.Setters list to be invoked.
[read-only]
SettersIList<Setter>. Gets the list of Setter objects that will be applied when the list of conditions in the MultiTrigger.Conditions property are all met.