Esempio n. 1
0
        /// <summary>
        /// Adds a new dual binding between the control and the specified source binding
        /// </summary>
        /// <param name="widgetPropertyName">Property on the control to update</param>
        /// <param name="sourceBinding">Binding to get/set the value to from the control</param>
        /// <param name="mode">Mode of the binding</param>
        /// <returns>A new instance of the DualBinding class that is used to control the binding</returns>
        public DualBinding <T> Bind <T>(string widgetPropertyName, DirectBinding <T> sourceBinding, DualBindingMode mode = DualBindingMode.TwoWay)
        {
            var binding = new DualBinding <T>(
                sourceBinding,
                new ControlBinding <Control, T>(this, new PropertyBinding <T>(widgetPropertyName)),
                mode
                );

            Bindings.Add(binding);
            return(binding);
        }
Esempio n. 2
0
        /// <summary>
        /// Adds a new dual binding between the control and the specified source binding
        /// </summary>
        /// <param name="bindable">Bindable object to add the binding to</param>
        /// <param name="widgetPropertyName">Property on the control to update</param>
        /// <param name="sourceBinding">Binding to get/set the value to from the control</param>
        /// <param name="mode">Mode of the binding</param>
        /// <returns>A new instance of the DualBinding class that is used to control the binding</returns>
        public static DualBinding <T> Bind <T>(this IBindable bindable, string widgetPropertyName, DirectBinding <T> sourceBinding, DualBindingMode mode = DualBindingMode.TwoWay)
        {
            var binding = new DualBinding <T>(
                sourceBinding,
                new BindableBinding <IBindable, T>(bindable, Binding.Property <T>(widgetPropertyName)),
                mode
                );

            bindable.Bindings.Add(binding);
            return(binding);
        }
Esempio n. 3
0
        /// <summary>
        /// Adds a new dual binding between the control and the specified source binding
        /// </summary>
        /// <param name="widgetPropertyName">Property on the control to update</param>
        /// <param name="sourceBinding">Binding to get/set the value to from the control</param>
        /// <param name="mode">Mode of the binding</param>
        /// <returns>A new instance of the DualBinding class that is used to control the binding</returns>
        public DualBinding Bind(string widgetPropertyName, DirectBinding sourceBinding, DualBindingMode mode = DualBindingMode.TwoWay)
        {
            var binding = new DualBinding(
                sourceBinding,
                new ObjectBinding(this, widgetPropertyName),
                mode
                );

            Bindings.Add(binding);
            return(binding);
        }
Esempio n. 4
0
        /// <summary>
        /// Adds a new dual binding between the control and the specified object
        /// </summary>
        /// <param name="propertyName">Property on the control to update</param>
        /// <param name="source">Object to bind to</param>
        /// <param name="sourcePropertyName">Property on the source object to retrieve/set the value of</param>
        /// <param name="mode">Mode of the binding</param>
        /// <returns>A new instance of the DualBinding class that is used to control the binding</returns>
        public DualBinding <T> Bind <T>(string propertyName, object source, string sourcePropertyName, DualBindingMode mode = DualBindingMode.TwoWay)
        {
            var binding = new DualBinding <T>(
                source,
                sourcePropertyName,
                this,
                propertyName,
                mode
                );

            Bindings.Add(binding);
            return(binding);
        }
Esempio n. 5
0
        /// <summary>
        /// Adds a new dual binding between the control and the specified object
        /// </summary>
        /// <param name="bindable">Bindable object to add the binding to</param>
        /// <param name="propertyName">Property on the control to update</param>
        /// <param name="source">Object to bind to</param>
        /// <param name="sourcePropertyName">Property on the source object to retrieve/set the value of</param>
        /// <param name="mode">Mode of the binding</param>
        /// <returns>A new instance of the DualBinding class that is used to control the binding</returns>
        public static DualBinding <T> Bind <T>(this IBindable bindable, string propertyName, object source, string sourcePropertyName, DualBindingMode mode = DualBindingMode.TwoWay)
        {
            var binding = new DualBinding <T>(
                source,
                sourcePropertyName,
                bindable,
                propertyName,
                mode
                );

            bindable.Bindings.Add(binding);
            return(binding);
        }
Esempio n. 6
0
        /// <summary>
        /// Binds to an object's <see cref="IBindable.DataContext"/> using the specified <paramref name="dataContextBinding"/>.
        /// </summary>
        /// <remarks>
        /// This creates a <see cref="DualBinding{TValue}"/> between a binding to the specified <paramref name="dataContextBinding"/> and this binding.
        /// Since the data context changes, the binding passed for the data context binding is an indirect binding, in that it is reused.
        /// The binding is added to the <see cref="IBindable.Bindings"/> collection.
        /// </remarks>
        /// <returns>A new dual binding that binds the <paramref name="dataContextBinding"/> to this control binding.</returns>
        /// <param name="dataContextBinding">Binding to get/set values from/to the control's data context.</param>
        /// <param name="mode">Dual binding mode.</param>
        /// <param name="defaultControlValue">Default control value.</param>
        /// <param name="defaultContextValue">Default context value.</param>
        public DualBinding <TValue> BindDataContext(IndirectBinding <TValue> dataContextBinding, DualBindingMode mode = DualBindingMode.TwoWay, TValue defaultControlValue = default(TValue), TValue defaultContextValue = default(TValue))
        {
            var control = DataItem;

            if (control == null)
            {
                throw new InvalidOperationException("Binding must be attached to a control");
            }
            var contextBinding = new BindableBinding <IBindable, object>(control, Binding.Delegate((IBindable w) => w.DataContext, null, (w, h) => w.DataContextChanged += h, (w, h) => w.DataContextChanged -= h));
            var valueBinding   = new ObjectBinding <object, TValue>(control.DataContext, dataContextBinding)
            {
                GettingNullValue = defaultControlValue,
                SettingNullValue = defaultContextValue,
                DataItem         = contextBinding.DataValue
            };
            DualBinding <TValue> binding = Bind(sourceBinding: valueBinding, mode: mode);

            contextBinding.DataValueChanged += delegate
            {
                ((ObjectBinding <object, TValue>)binding.Source).DataItem = contextBinding.DataValue;
            };
            control.Bindings.Add(contextBinding);
            return(binding);
        }