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
継承
System.Object
Trigger
属性
実装

注釈

クラスは 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 めます。 開発者は、この例では、ユーザーが文字列の編集を続けるときにテキストを既定の色に戻しませんが、開発者は、その結果を取得するために終了アクションを追加で実装して指定できることに注意してください。

以下の ColorTriggerAction クラスを名前空間で定義します TriggerDemo

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)

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

適用対象

こちらもご覧ください