Esempio n. 1
0
        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));
        }
Esempio n. 2
0
 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 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; }));
 }
Esempio n. 4
0
 /// <summary>
 /// A convenient method to create a new instance of the <see cref="BindableProperty" />
 /// class that represents <see cref="Modifier" />.
 /// </summary>
 /// <remarks>
 /// This sets <see cref="Modifier.Body" /> property and lets <see cref="Modifier" /> inherit <see cref="BindableObject.BindingContext" />.
 /// Those states must be maintained by the caller.
 /// </remarks>
 /// <param name="property">
 /// The name of the BindableProperty.
 /// </param>
 /// <param name="declarer">
 /// The type of the declaring object.
 /// </param>
 /// <param name="defaultValueCreator">
 /// A Func used to initialize default value for reference types.
 /// </param>
 protected static BindableProperty CreateBindableModifierProperty(string property, Type declarer, BindableProperty.CreateDefaultValueDelegate defaultValueCreator)
 {
     return(BindableProperty.Create(
                property,
                typeof(Modifier),
                declarer,
                null,
                BindingMode.OneWay,
                null,
                s_onBindingModifierPropertyChanged,
                null,
                null,
                defaultValueCreator));
 }
Esempio n. 5
0
        /// <summary>
        /// A convenient method to create a new instance of the <see cref="BindableProperty" />
        /// class that represents a field or property of the <see cref="Body" />.
        /// </summary>
        /// <param name="property">
        /// The name of the BindableProperty.
        /// </param>
        /// <param name="declarer">
        /// The type of the declaring object.
        /// </param>
        /// <param name="update">
        /// A method to update the component with the given value.
        /// </param>
        /// <param name="defaultValue">
        /// The default value for the property.
        /// </param>
        /// <param name="defaultBindingMode">
        /// The BindingMode to use on SetBinding() if no BindingMode is given. This parameter is optional. Default is BindingMode.OneWay.
        /// </param>
        /// <param name="defaultValueCreator">
        /// A Func used to initialize default value for reference types.
        /// </param>
        protected static BindableProperty CreateBindableBodyProperty <U>(string property, Type declarer, Action <T, U> update, U defaultValue = default(U), BindingMode defaultBindingMode = BindingMode.OneWay, BindableProperty.CreateDefaultValueDelegate defaultValueCreator = null)
        {
            return(BindableProperty.Create(property, typeof(U), declarer, defaultValue, defaultBindingMode, propertyChanged: (bindable, oldValue, newValue) =>
            {
                var body = ((Component <T>)bindable).Body;

                if (body != null)
                {
                    Forms.mainThread.Send(state => update(body, (U)state), newValue);
                }
            }, defaultValueCreator: defaultValueCreator));
        }