Binding.Create<TSource> 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
注意
现已弃用此 API。
这是一种方便的工厂方法,用于通过表达式而不是属性名称来创建绑定。 此 API 在重构方面更具弹性。
[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
类型参数
- TSource
绑定的源的类型。
参数
- propertyGetter
- System.Linq.Expressions.Expression<System.Func<TSource,System.Object>>
用于检索绑定路径的表达式。
- mode
- BindingMode
绑定模式。 此属性是可选的。 默认为 Default。
- converter
- IValueConverter
转换器。 此参数可选。 默认值为 null
。
- converterParameter
- System.Object
要传递到转换器的用户定义参数。 此参数可选。 默认值为 null
。
- stringFormat
- System.String
字符串格式。 此参数可选。 默认值为 null
。
返回
新建的绑定。
- 属性
-
System.ComponentModel.EditorBrowsableAttribute System.ObsoleteAttribute
注解
以下示例演示如何将绑定设置为属性 :
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".