public static BindableProperty Create <TDeclarer, TPropertyType>(string propertyName, TPropertyType defaultValue, BindingMode defaultBindingMode = BindingMode.OneWay, BindableProperty.ValidateValueDelegate <TPropertyType> validateValue = null, BindableProperty.BindingPropertyChangedDelegate <TPropertyType> propertyChanged = null, BindableProperty.BindingPropertyChangingDelegate <TPropertyType> propertyChanging = null, BindableProperty.CoerceValueDelegate <TPropertyType> coerceValue = null, BindableProperty.CreateDefaultValueDelegate <TDeclarer, TPropertyType> defaultValueCreator = null) where TDeclarer : BindableObject { BindableProperty.CreateDefaultValueDelegate dvc = null; if (defaultValueCreator != null) { dvc = (bindable) => defaultValueCreator((TDeclarer)bindable); } return(BindableProperty.Create(propertyName, typeof(TPropertyType), typeof(TDeclarer), defaultValue, defaultBindingMode, validateValue: (bindable, value) => { return validateValue != null ? validateValue(bindable, (TPropertyType)value) : true; }, propertyChanged: (bindable, oldValue, newValue) => { if (propertyChanged != null) { propertyChanged(bindable, (TPropertyType)oldValue, (TPropertyType)newValue); } }, propertyChanging: (bindable, oldValue, newValue) => { if (propertyChanging != null) { propertyChanging(bindable, (TPropertyType)oldValue, (TPropertyType)newValue); } }, coerceValue: (bindable, value) => { return coerceValue != null ? coerceValue(bindable, (TPropertyType)value) : value; }, defaultValueCreator: dvc)); }
public static BindableProperty Create <TDeclarer, TPropertyType>(Expression <Func <TDeclarer, TPropertyType> > getter, TPropertyType defaultValue, BindingMode defaultBindingMode = BindingMode.OneWay, BindableProperty.ValidateValueDelegate <TPropertyType> validateValue = null, BindableProperty.BindingPropertyChangedDelegate <TPropertyType> propertyChanged = null, BindableProperty.BindingPropertyChangingDelegate <TPropertyType> propertyChanging = null, BindableProperty.CoerceValueDelegate <TPropertyType> coerceValue = null, BindableProperty.CreateDefaultValueDelegate <TDeclarer, TPropertyType> defaultValueCreator = null) where TDeclarer : BindableObject { return(Create <TDeclarer, TPropertyType>(GetPropertyPath(getter), defaultValue, defaultBindingMode, validateValue, propertyChanged, propertyChanging, coerceValue, defaultValueCreator)); }
public void CreateForGeneric() { const BindingMode mode = BindingMode.OneWayToSource; const string dvalue = "default"; BindableProperty.CoerceValueDelegate coerce = (bindable, value) => value; BindableProperty.ValidateValueDelegate validate = (b, v) => true; BindableProperty.BindingPropertyChangedDelegate changed = (b, ov, nv) => { }; BindableProperty.BindingPropertyChangingDelegate changing = (b, ov, nv) => { }; var prop = BindableProperty.Create("Text", typeof(string), typeof(GenericView <>), dvalue, mode, validate, changed, changing, coerce); Assert.AreEqual("Text", prop.PropertyName); Assert.AreEqual(typeof(GenericView <>), prop.DeclaringType); Assert.AreEqual(typeof(string), prop.ReturnType); Assert.AreEqual(dvalue, prop.DefaultValue); Assert.AreEqual(mode, prop.DefaultBindingMode); }
public static BindableProperty Create <TDeclarer, TPropertyType>(Expression <Func <TDeclarer, TPropertyType> > getter, TPropertyType defaultValue, BindingMode defaultBindingMode = BindingMode.OneWay, BindableProperty.ValidateValueDelegate <TPropertyType> validateValue = null, BindableProperty.BindingPropertyChangedDelegate <TPropertyType> propertyChanged = null, BindableProperty.BindingPropertyChangingDelegate <TPropertyType> propertyChanging = null, BindableProperty.CoerceValueDelegate <TPropertyType> coerceValue = null, BindableProperty.CreateDefaultValueDelegate <TDeclarer, TPropertyType> defaultValueCreator = null) where TDeclarer : BindableObject { return(BindableProperty.Create(ExpressionExtension.GetPropertyPath(getter), typeof(TPropertyType), typeof(TDeclarer), defaultValue, defaultBindingMode, validateValue: (bindable, value) => { return validateValue != null ? validateValue(bindable, (TPropertyType)value) : true; }, propertyChanged: (bindable, oldValue, newValue) => { if (propertyChanged != null) { propertyChanged(bindable, (TPropertyType)oldValue, (TPropertyType)newValue); } }, propertyChanging: (bindable, oldValue, newValue) => { if (propertyChanging != null) { propertyChanging(bindable, (TPropertyType)oldValue, (TPropertyType)newValue); } }, coerceValue: (bindable, value) => { return coerceValue != null ? coerceValue(bindable, (TPropertyType)value) : value; }, defaultValueCreator: (bindable) => { return defaultValueCreator != null ? defaultValueCreator((TDeclarer)bindable) : defaultValue; })); }