共用方式為


DataTrigger 類別

定義

代表任意繫結上條件的類別,以及滿足條件時會套用的 Setter 物件清單。

[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
繼承
System.Object
DataTrigger
屬性
實作

備註

類別 DataTrigger 適用於檢查其他控制件上的值,以及已加入它之控件上的任何屬性。 也就是說,其預設系結內容是其新增至其中的控件。

下列 XML 範例會提示使用者輸入秘密,也就是「文字色彩為綠色」。 當使用者輸入 「The」 時,[專案] 文字會將色彩變更為紅色。 當使用者完成秘密時,標籤文字會變成綠色。 如果使用者接著編輯秘密,程式代碼會回復為預設色彩。 此範例示範如何從 Entry) 系結至封閉控件 (Entry,以及系結至卷標) 的 Arbitary 控件 (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 進行比較,以判斷何時應叫用 setter。

BindingContext

取得或設定物件,這個物件包含屬於此 BindableObject 屬性繫結屬性將設為目標的屬性。

(繼承來源 BindableObject)
Dispatcher

代表任意繫結上條件的類別,以及滿足條件時會套用的 Setter 物件清單。

(繼承來源 BindableObject)
EnterActions

取得符合觸發條件時要叫用的 TriggerAction 物件清單。 若為 EventTrigger 類別請予以略過。

(繼承來源 TriggerBase)
ExitActions

取得觸發條件不再符合之後要叫用的 TriggerAction 物件清單。 若為 EventTrigger 類別請予以略過。

(繼承來源 TriggerBase)
IsSealed

取得值,指出是否密封觸發程序。

(繼承來源 TriggerBase)
Setters

取得物件清單,當屬性所Binding命名的系結變成等於 Value時,將套用的物件清單Setter

TargetType

可附加這個 TriggerBase 物件的目標物件類型。

(繼承來源 TriggerBase)
Value

取得或設定繫結的值,由 Binding 屬性命名,此值會導致套用 setter。

方法

ApplyBindings()

將繫結套用至 BindingContext

(繼承來源 BindableObject)
ClearValue(BindableProperty)

清除 SetValue 針對 property 所設定的任何值。

(繼承來源 BindableObject)
ClearValue(BindablePropertyKey)

清除 SetValue 針對 propertyKey 所識別屬性設定的任何值。

(繼承來源 BindableObject)
CoerceValue(BindableProperty)

代表任意繫結上條件的類別,以及滿足條件時會套用的 Setter 物件清單。

(繼承來源 BindableObject)
CoerceValue(BindablePropertyKey)

代表任意繫結上條件的類別,以及滿足條件時會套用的 Setter 物件清單。

(繼承來源 BindableObject)
GetValue(BindableProperty)

傳回 BindableProperty 中包含的值。

(繼承來源 BindableObject)
GetValues(BindableProperty, BindableProperty, BindableProperty)
已淘汰.

供 Xamarin.Forms 平台內部使用。

(繼承來源 BindableObject)
GetValues(BindableProperty, BindableProperty)
已淘汰.

供 Xamarin.Forms 平台內部使用。

(繼承來源 BindableObject)
IsSet(BindableProperty)

如果目標屬性存在且已設定,則傳回 true

(繼承來源 BindableObject)
OnBindingContextChanged()

覆寫此方法,以在 BindingContext 變更時執行動作。

(繼承來源 BindableObject)
OnPropertyChanged(String)

從子類別呼叫這個方法,以通知屬性發生了變更。

(繼承來源 BindableObject)
OnPropertyChanging(String)

從子類別呼叫這個方法,以通知屬性即將發生變更。

(繼承來源 BindableObject)
RemoveBinding(BindableProperty)

移除先前設定的繫結。

(繼承來源 BindableObject)
SetBinding(BindableProperty, BindingBase)

將繫結指派給屬性。

(繼承來源 BindableObject)
SetValue(BindableProperty, Object)

設定指定之屬性的值。

(繼承來源 BindableObject)
SetValue(BindablePropertyKey, Object)

設定 propertyKey 的值。

(繼承來源 BindableObject)
SetValueCore(BindableProperty, Object, SetValueFlags)

供 Xamarin.Forms 平台內部使用。

(繼承來源 BindableObject)
UnapplyBindings()

取消套用所有先前設定的繫結。

(繼承來源 BindableObject)

事件

BindingContextChanged

每當 BindingContext 屬性變更時引發。

(繼承來源 BindableObject)
PropertyChanged

在屬性變更時引發。

(繼承來源 BindableObject)
PropertyChanging

在屬性即將變更時引發。

(繼承來源 BindableObject)

明確介面實作

IDynamicResourceHandler.SetDynamicResource(BindableProperty, String)

供 Xamarin.Forms 平台內部使用。

(繼承來源 BindableObject)
IValueProvider.ProvideValue(IServiceProvider)

供 XAML 基礎結構內部使用。

擴充方法

GetPropertyIfSet<T>(BindableObject, BindableProperty, T)

代表任意繫結上條件的類別,以及滿足條件時會套用的 Setter 物件清單。

SetAppThemeColor(BindableObject, BindableProperty, Color, Color)

代表任意繫結上條件的類別,以及滿足條件時會套用的 Setter 物件清單。

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

建立並將繫結套用至屬性。

SetBinding<TSource>(BindableObject, BindableProperty, Expression<Func<TSource,Object>>, BindingMode, IValueConverter, String)
已淘汰.

從運算式建立及套用繫結。

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

代表任意繫結上條件的類別,以及滿足條件時會套用的 Setter 物件清單。

適用於