DataTrigger Class
Definition
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.
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.
[Xamarin.Forms.ContentProperty("Setters")]
[Xamarin.Forms.Xaml.AcceptEmptyServiceProvider]
public sealed class DataTrigger : Xamarin.Forms.TriggerBase, Xamarin.Forms.Xaml.IValueProvider
type DataTrigger = class
inherit TriggerBase
interface IValueProvider
- Inheritance
- Attributes
- Implements
Remarks
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 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="Can you tell me the secret?" VerticalOptions="Center" HorizontalOptions="Center">
<Label.Triggers>
<DataTrigger TargetType="Label"
Binding="{Binding Source={x:Reference checkEntry},
Path=Text}"
Value="The text color is green">
<Setter Property="TextColor" Value="Color.Green" />
</DataTrigger>
</Label.Triggers>
</Label>
<Entry Placeholder="Type the secret here." x:Name="checkEntry" VerticalOptions="Center" HorizontalOptions="Center">
<Entry.Triggers>
<DataTrigger TargetType="Entry"
Binding="{Binding Text}"
Value="The">
<Setter Property="TextColor" Value="Red" />
</DataTrigger>
</Entry.Triggers>
</Entry>
</StackLayout>
</ContentPage>
Constructors
DataTrigger(Type) |
Initializes a new DataTrigger instance. |
Properties
Binding |
Gets or sets the binding whose value will be compared to Value to determine when to invoke the setters. |
BindingContext |
Gets or sets object that contains the properties that will be targeted by the bound properties that belong to this BindableObject. (Inherited from BindableObject) |
Dispatcher | (Inherited from BindableObject) |
EnterActions |
Gets the list of TriggerAction objects that will be invoked when the trigger condition is met. Ignored for the EventTrigger class. (Inherited from TriggerBase) |
ExitActions |
Gets the list of TriggerAction objects that will be invoked after the trigger condition is no longer met. Ignored for the EventTrigger class. (Inherited from TriggerBase) |
IsSealed |
Gets a value that indicates whether or not the trigger is sealed. (Inherited from TriggerBase) |
Setters |
Gets the list of Setter objects that will be applied when the binding that is named by the Binding property becomes equal to Value. |
TargetType |
The type of object to which this TriggerBase object can be attached. (Inherited from TriggerBase) |
Value |
Gets or sets the value of the binding, named by the Binding property, that will cause the setters to be applied. |
Methods
ApplyBindings() |
Apply the bindings to BindingContext. (Inherited from BindableObject) |
ClearValue(BindableProperty) |
Clears any value set by SetValue for |
ClearValue(BindablePropertyKey) |
Clears any value set by SetValue for the property that is identified by |
CoerceValue(BindableProperty) | (Inherited from BindableObject) |
CoerceValue(BindablePropertyKey) | (Inherited from BindableObject) |
GetValue(BindableProperty) |
Returns the value that is contained in the BindableProperty. (Inherited from BindableObject) |
GetValues(BindableProperty, BindableProperty, BindableProperty) |
Obsolete.
For internal use by the Xamarin.Forms platform. (Inherited from BindableObject) |
GetValues(BindableProperty, BindableProperty) |
Obsolete.
For internal use by the Xamarin.Forms platform. (Inherited from BindableObject) |
IsSet(BindableProperty) |
Returns |
OnBindingContextChanged() |
Override this method to execute an action when the BindingContext changes. (Inherited from BindableObject) |
OnPropertyChanged(String) |
Call this method from a child class to notify that a change happened on a property. (Inherited from BindableObject) |
OnPropertyChanging(String) |
Call this method from a child class to notify that a change is going to happen on a property. (Inherited from BindableObject) |
RemoveBinding(BindableProperty) |
Removes a previously set binding. (Inherited from BindableObject) |
SetBinding(BindableProperty, BindingBase) |
Assigns a binding to a property. (Inherited from BindableObject) |
SetValue(BindableProperty, Object) |
Sets the value of the specified property. (Inherited from BindableObject) |
SetValue(BindablePropertyKey, Object) |
Sets the value of the propertyKey. (Inherited from BindableObject) |
SetValueCore(BindableProperty, Object, SetValueFlags) |
For internal use by the Xamarin.Forms platform. (Inherited from BindableObject) |
UnapplyBindings() |
Unapplies all previously set bindings. (Inherited from BindableObject) |
Events
BindingContextChanged |
Raised whenever the BindingContext property changes. (Inherited from BindableObject) |
PropertyChanged |
Raised when a property has changed. (Inherited from BindableObject) |
PropertyChanging |
Raised when a property is about to change. (Inherited from BindableObject) |
Explicit Interface Implementations
IDynamicResourceHandler.SetDynamicResource(BindableProperty, String) |
For internal use by the Xamarin.Forms platform. (Inherited from BindableObject) |
IValueProvider.ProvideValue(IServiceProvider) |
For internal use by the XAML infrastructure. |
Extension Methods
GetPropertyIfSet<T>(BindableObject, BindableProperty, T) | |
SetAppThemeColor(BindableObject, BindableProperty, Color, Color) | |
SetBinding(BindableObject, BindableProperty, String, BindingMode, IValueConverter, String) |
Creates and applies a binding to a property. |
SetBinding<TSource>(BindableObject, BindableProperty, Expression<Func<TSource,Object>>, BindingMode, IValueConverter, String) |
Obsolete.
Creates and applies a binding from an expression. |
SetOnAppTheme<T>(BindableObject, BindableProperty, T, T) |