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
System.String

바인딩할 속성 경로를 나타내는 System.String입니다.

mode
BindingMode

바인딩의 BindingMode입니다. 이 매개 변수는 선택적 요소입니다. 기본값은 Default입니다.

converter
IValueConverter

바인딩의 IValueConverter입니다. 이 매개 변수는 선택적 요소입니다. 기본값은 null입니다.

stringFormat
System.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
System.Linq.Expressions.Expression<System.Func<TSource,System.Object>>

원본 경로를 검색하는 데 사용되는 식입니다.

mode
BindingMode

바인딩용 BindingMode입니다. 이 매개 변수는 선택적 요소입니다. 기본값은 Default입니다.

converter
IValueConverter

바인딩용 IValueConverter입니다. 이 매개 변수는 선택적 요소입니다. 기본값은 null입니다.

stringFormat
System.String

바인딩의 stringFormat으로 사용되는 문자열입니다. 이 매개 변수는 선택적 요소입니다. 기본값은 null입니다.

특성
System.ComponentModel.EditorBrowsableAttribute System.ObsoleteAttribute

설명

이 확장 메서드는 경로 대신 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"

적용 대상