BindableObjectExtensions.SetBinding メソッド

定義

オーバーロード

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

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

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

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

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

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

public static void SetBinding (this Xamarin.Forms.BindableObject self, Xamarin.Forms.BindableProperty targetProperty, string path, Xamarin.Forms.BindingMode mode = Xamarin.Forms.BindingMode.Default, Xamarin.Forms.IValueConverter converter = default, string stringFormat = default);
static member SetBinding : Xamarin.Forms.BindableObject * Xamarin.Forms.BindableProperty * string * Xamarin.Forms.BindingMode * Xamarin.Forms.IValueConverter * string -> unit

パラメーター

targetProperty
BindableProperty

バインディングを設定する BindableProperty。

path
String

バインド先のプロパティ パスを示す String

mode
BindingMode

バインディングの BindingMode。 このパラメーターは省略できます。 既定値は Default です。

converter
IValueConverter

バインド用の IValueConverter。 このパラメーターは省略できます。 既定値は null です。

stringFormat
String

バインド用の stringFormat として使用される文字列。 このパラメーターは省略できます。 既定値は null です。

注釈

次の例は、拡張メソッドを使用してバインドを設定する方法を示しています。

public class PersonViewModel
{
    public string Name { get; set; }
    public string Company { get; set; }
}

// ...

var vm = new PersonViewModel {
    Name = "John Doe", 
    Company = "Xamarin"
}

var label = new Label ();
label.SetBinding (Label.TextProperty, "Name"); // "Name" is the property on the view model
label.BindingContext = vm;

Debug.WriteLine (label.Text); // prints "John Doe"

適用対象

SetBinding<TSource>(BindableObject, BindableProperty, Expression<Func<TSource,Object>>, BindingMode, IValueConverter, String)

注意事項

この API は非推奨になりました。

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

[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
[System.Obsolete]
public static void SetBinding<TSource> (this Xamarin.Forms.BindableObject self, Xamarin.Forms.BindableProperty targetProperty, System.Linq.Expressions.Expression<Func<TSource,object>> sourceProperty, Xamarin.Forms.BindingMode mode = Xamarin.Forms.BindingMode.Default, Xamarin.Forms.IValueConverter converter = default, string stringFormat = default);
static member SetBinding : Xamarin.Forms.BindableObject * Xamarin.Forms.BindableProperty * System.Linq.Expressions.Expression<Func<'Source, obj>> * Xamarin.Forms.BindingMode * Xamarin.Forms.IValueConverter * string -> unit

型パラメーター

TSource

変換元の型です。

パラメーター

self
BindableObject

BindableObject。

targetProperty
BindableProperty

バインドする BindableProperty

sourceProperty
Expression<Func<TSource,Object>>

ソース パスを取得するために使用する式。

mode
BindingMode

バインド用の BindingMode。 このパラメーターは省略できます。 既定値は Default です。

converter
IValueConverter

バインド用の IValueConverter。 このパラメーターは省略できます。 既定値は null です。

stringFormat
String

バインド用の stringFormat として使用される文字列。 このパラメーターは省略できます。 既定値は null です。

属性

注釈

この拡張メソッドは、path ではなく Expression を使用してバインディングを作成および設定します。 式を使用すると、リファクタリングがわかりやすくなっています。

次の例は、拡張メソッドを使用したバインディングの設定を示しています。

public class PersonViewModel
{
    public string Name { get; set; }
    public string Company { get; set; }
}

// ...

var vm = new PersonViewModel {
    Name = "John Doe", 
    Company = "Xamarin"
};

var label = new Label ();
label.SetBinding<PersonViewModel> (Label.TextProperty, vm => vm.Name);  // "Name" is the property on the view model
label.BindingContext = vm;

Debug.WriteLine (label.Text); // prints "John Doe"

適用対象