DataTrigger 类

定义

表示任意绑定条件的类,以及满足条件时将应用的 Setter 对象列表。

public ref class DataTrigger sealed : Microsoft::Maui::Controls::TriggerBase, Microsoft::Maui::Controls::Xaml::IValueProvider
[Microsoft.Maui.Controls.ContentProperty("Setters")]
[Microsoft.Maui.Controls.Xaml.AcceptEmptyServiceProvider]
public sealed class DataTrigger : Microsoft.Maui.Controls.TriggerBase, Microsoft.Maui.Controls.Xaml.IValueProvider
[<Microsoft.Maui.Controls.ContentProperty("Setters")>]
[<Microsoft.Maui.Controls.Xaml.AcceptEmptyServiceProvider>]
type DataTrigger = class
    inherit TriggerBase
    interface IValueProvider
Public NotInheritable Class DataTrigger
Inherits TriggerBase
Implements IValueProvider
继承
属性
实现

注解

DataTrigger 适用于检查其他控件上的值,以及已添加该类的控件上的任何属性。 也就是说,其默认绑定上下文是已将其添加到的控件。

下面的 XML 示例提示用户键入机密,即“文本颜色为绿色”。 当用户键入“The”时,“输入”文本将颜色更改为红色。 当用户完成机密时,“标签”文本将变为绿色。 如果用户随后编辑机密,则代码将恢复为默认颜色。 此示例演示如何绑定到封闭控件 (Entry from Entry) ,以及绑定到一个仲裁控件 (Label 中的 Entry)

<?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>

构造函数

DataTrigger(Type)

初始化一个新 DataTrigger 实例。

属性

Binding

获取或设置其值将与 Value 进行比较以确定何时调用资源库的绑定。

BindingContext

获取或设置一个 对象,该对象包含属于此 BindableObject的绑定属性的目标属性。 这是一种可绑定属性。

(继承自 BindableObject)
Dispatcher

获取创建此可绑定对象时可用的调度程序,否则尝试查找最近的可用调度程序 (可能为窗口/应用的) 。

(继承自 BindableObject)
EnterActions

获取将在满足触发条件时调用的 TriggerAction 对象的列表。 忽略 EventTrigger 类。

(继承自 TriggerBase)
ExitActions

获取在不再满足触发条件时调用的 TriggerAction 对象的列表。 忽略 EventTrigger 类。

(继承自 TriggerBase)
IsSealed

获取一个值,该值指示触发器是否密封。

(继承自 TriggerBase)
Setters

获取当由 Binding 属性命名的Setter绑定等于 Value时将应用的对象列表。

TargetType

TriggerBase 对象可附加到的对象类型。

(继承自 TriggerBase)
Value

获取或设置由 Binding 属性命名的绑定的值,它将导致资源库被应用。

方法

ApplyBindings()

将所有当前绑定应用于 BindingContext

(继承自 BindableObject)
ClearValue(BindableProperty)

清除以前为可绑定属性设置的任何值。

(继承自 BindableObject)
ClearValue(BindablePropertyKey)

清除以前为可绑定属性设置的任何值(由其键标识)。

(继承自 BindableObject)
CoerceValue(BindableProperty)

强制指定可绑定属性的值。 这是通过调用 BindableProperty.CoerceValueDelegate 指定的可绑定属性来完成的。

(继承自 BindableObject)
CoerceValue(BindablePropertyKey)

强制指定可绑定属性的值。 这是通过调用 BindableProperty.CoerceValueDelegate 指定的可绑定属性来完成的。

(继承自 BindableObject)
GetValue(BindableProperty)

返回给定可绑定属性中包含的值。

(继承自 BindableObject)
IsSet(BindableProperty)

确定可绑定属性是否存在并且是否设置了值。

(继承自 BindableObject)
OnBindingContextChanged()

引发 BindingContextChanged 事件。

(继承自 BindableObject)
OnPropertyChanged(String)

引发 PropertyChanged 事件。

(继承自 BindableObject)
OnPropertyChanging(String)

引发 PropertyChanging 事件。

(继承自 BindableObject)
RemoveBinding(BindableProperty)

从可绑定属性中删除以前设置的绑定。

(继承自 BindableObject)
SetBinding(BindableProperty, BindingBase)

将绑定分配给可绑定属性。

(继承自 BindableObject)
SetValue(BindableProperty, Object)

设置指定的可绑定属性的值。

(继承自 BindableObject)
SetValue(BindablePropertyKey, Object)

设置指定的可绑定属性的值。

(继承自 BindableObject)
UnapplyBindings()

从当前上下文中删除所有当前绑定。

(继承自 BindableObject)

事件

BindingContextChanged

BindingContext 属性的值更改时发生。

(继承自 BindableObject)
PropertyChanged

在属性值更改时发生。

(继承自 BindableObject)
PropertyChanging

在属性值更改时发生。

(继承自 BindableObject)

显式接口实现

IDynamicResourceHandler.SetDynamicResource(BindableProperty, String)

表示任意绑定条件的类,以及满足条件时将应用的 Setter 对象列表。

(继承自 BindableObject)
IValueProvider.ProvideValue(IServiceProvider)

表示任意绑定条件的类,以及满足条件时将应用的 Setter 对象列表。

扩展方法

GetPropertyIfSet<T>(BindableObject, BindableProperty, T)

表示任意绑定条件的类,以及满足条件时将应用的 Setter 对象列表。

SetAppTheme<T>(BindableObject, BindableProperty, T, T)

表示任意绑定条件的类,以及满足条件时将应用的 Setter 对象列表。

SetAppThemeColor(BindableObject, BindableProperty, Color, Color)

表示任意绑定条件的类,以及满足条件时将应用的 Setter 对象列表。

SetBinding(BindableObject, BindableProperty, String, BindingMode, IValueConverter, String)

创建绑定并将其应用到属性。

适用于