Share via


Binding.Create<TSource> Method

Definition

Caution

This API is now deprecated.

This is a convenient factory method to create a binding from an expression, instead of a property name. This api is more resilient to refactoring.

[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
[System.Obsolete]
public static Xamarin.Forms.Binding Create<TSource> (System.Linq.Expressions.Expression<Func<TSource,object>> propertyGetter, Xamarin.Forms.BindingMode mode = Xamarin.Forms.BindingMode.Default, Xamarin.Forms.IValueConverter converter = default, object converterParameter = default, string stringFormat = default);
static member Create : System.Linq.Expressions.Expression<Func<'Source, obj>> * Xamarin.Forms.BindingMode * Xamarin.Forms.IValueConverter * obj * string -> Xamarin.Forms.Binding

Type Parameters

TSource

The type of the source of the binding.

Parameters

propertyGetter
System.Linq.Expressions.Expression<System.Func<TSource,System.Object>>

An expression used to retrieve the binding path.

mode
BindingMode

The binding mode. This property is optional. Default is Default.

converter
IValueConverter

The converter. This parameter is optional. Default is null.

converterParameter
System.Object

An user-defined parameter to pass to the converter. This parameter is optional. Default is null.

stringFormat
System.String

A String format. This parameter is optional. Default is null.

Returns

A newly created binding.

Attributes
System.ComponentModel.EditorBrowsableAttribute System.ObsoleteAttribute

Remarks

The following example shows how to set a binding to a property :

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

var label = new Label ();
PersonViewModel person;
label.BindingContext = person = new PersonViewModel { Name = "John Doe", Company = "Microsoft" };
label.SetBinding (Label.TextProperty, Binding.Create<PersonViewModel> (vm => vm.Name));
Debug.WriteLine (label.Text); //prints "John Doe".

Applies to