Trigger クラス

定義

プロパティ条件と、その条件が満たされたときに実行されるアクションを表すクラス。

[Xamarin.Forms.ContentProperty("Setters")]
[Xamarin.Forms.Xaml.AcceptEmptyServiceProvider]
public sealed class Trigger : Xamarin.Forms.TriggerBase, Xamarin.Forms.Xaml.IValueProvider
type Trigger = class
    inherit TriggerBase
    interface IValueProvider
継承
属性
実装

注釈

クラスは、 Trigger 追加されたコントロールのプロパティの値を確認するのに適しています。 つまり、既定のバインディングコンテキストは、追加されたコントロールです。 親以外のコントロールにバインドするには、開発者がクラスを代わりに使用する必要があり DataTrigger ます。

次の XML の例では、ユーザーにシークレットを入力するように求められています。つまり、"テキストの色は赤" です。 ユーザーがシークレットを入力すると、入力テキストが赤に変わります。 ユーザーがシークレットと異なるテキストを編集した場合、コードは既定の色に戻ります。 この例では、トリガーを使用して、外側のコントロールにバインドする方法を示します。


<?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="Tell me the secret"
               VerticalOptions="Center"
               HorizontalOptions="Center" />
<Entry Placeholder="Type the secret here."
               VerticalOptions="Center"
               HorizontalOptions="Center">
<Entry.Triggers>
<Trigger TargetType="Entry"
                    Property="Text"
                    Value="The text color is red">
<Setter Property="TextColor" Value="Red" />
</Trigger>
</Entry.Triggers>
</Entry>
</StackLayout>
</ContentPage>

次の例は、開発者がトリガーを使用してイベントに応答し、クラスを使用してコントロールプロパティの値を更新する方法を示して TriggerAction<T> います。 この例では、テキストの色に関する質問に回答するようにユーザーに求め、 ColorTriggerActionを呼び出して、ユーザーが「テキストの色が赤」と入力したときにテキストを赤にします。 この例では、ユーザーが文字列の編集を続けると、テキストが既定の色に変更されないことに注意する必要がありますが、開発者はさらにを実装し、その結果を取得するための終了アクションを指定することもできます。

次のように、 Triggerdemo名前空間で定義されている ColorTriggerAction クラスを使用します。

public class ColorTriggerAction : TriggerAction<Entry>
{
    protected override void Invoke(Entry sender)
    {
        sender.TextColor = Color.Red;
    }
}

開発者は、次の XAML を使用して、テキスト領域の色を赤に変更することで、秘密の文字列に応答するページを作成でき 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="What color is &quot;The text&quot;?"
               VerticalOptions="Center"
               HorizontalOptions="Center" />
<Entry Placeholder="Type answer here."
               VerticalOptions="Center"
               HorizontalOptions="Center"
               BackgroundColor="White">
<Entry.Triggers>
<Trigger TargetType="Entry"
                         Property="Text"
                         Value="The text is red" >
<Trigger.EnterActions>
<local:ColorTriggerAction />
</Trigger.EnterActions>
</Trigger>
</Entry.Triggers>
</Entry>
</StackLayout>
</ContentPage>

コンストラクター

Trigger(Type)

新しい Trigger インスタンスを初期化します。

プロパティ

BindingContext

バインドされたプロパティのうち、この BindableObject に属するプロパティの対象となるプロパティが含まれるオブジェクトを取得または設定します。

(継承元 BindableObject)
Dispatcher (継承元 BindableObject)
EnterActions

トリガー条件が満たされたときに呼び出される TriggerAction オブジェクトの一覧を取得します。 EventTrigger クラスの場合、無視されます。

(継承元 TriggerBase)
ExitActions

トリガー条件が満たされなくなった後に呼び出される TriggerAction オブジェクトの一覧を取得します。 EventTrigger クラスの場合、無視されます。

(継承元 TriggerBase)
IsSealed

トリガーが封印されているかどうかを示す値を取得します。

(継承元 TriggerBase)
Property

セッターを呼び出すタイミングを決定するために Value と比較される値を持つプロパティを取得または設定します。

Setters

Property で指定されたプロパティが Value と等しくなった場合に適用される Setter オブジェクトのリストを取得します。

TargetType

この TriggerBase オブジェクトを添付できるオブジェクトの型。

(継承元 TriggerBase)
Value

セッターを適用する、Property プロパティによって指定されたプロパティの値を取得または設定します。

メソッド

ApplyBindings()

BindingContext にバインディングを適用します。

(継承元 BindableObject)
ClearValue(BindableProperty)

propertySetValue によって設定された値を消去します。

(継承元 BindableObject)
ClearValue(BindablePropertyKey)

propertyKey によって識別されるプロパティの SetValue によって設定される値を消去します。

(継承元 BindableObject)
CoerceValue(BindableProperty) (継承元 BindableObject)
CoerceValue(BindablePropertyKey) (継承元 BindableObject)
GetValue(BindableProperty)

BindableProperty に含まれる値を返します。

(継承元 BindableObject)
GetValues(BindableProperty, BindableProperty)
互換性のために残されています。

Xamarin.Forms プラットフォームによる内部使用向け。

(継承元 BindableObject)
GetValues(BindableProperty, 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)

Xamarin.Forms プラットフォームによる内部使用向け。

拡張メソッド

GetPropertyIfSet<T>(BindableObject, BindableProperty, T)
SetAppThemeColor(BindableObject, BindableProperty, Color, Color)
SetBinding(BindableObject, BindableProperty, String, BindingMode, IValueConverter, String)

プロパティにバインドを作成し、適用します。

SetBinding<TSource>(BindableObject, BindableProperty, Expression<Func<TSource,Object>>, BindingMode, IValueConverter, String)
互換性のために残されています。

式からバインドを作成し適用します。

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

適用対象

こちらもご覧ください