示例#1
0
		public static DualBinding Bind (this Widget widget, string widgetPropertyName, ObjectBinding sourceBinding, DualBindingMode mode = DualBindingMode.TwoWay)
		{
			var binding = new DualBinding (
				sourceBinding,
				new ObjectSingleBinding(widget, widgetPropertyName),
				mode
			);
			widget.Bindings.Add (binding);
			return binding;
		}
示例#2
0
        /// <summary>
        /// Adds a new dual binding between the control and the specified source binding
        /// </summary>
        /// <param name="control">Control 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 Bind(this Control control, string widgetPropertyName, DirectBinding sourceBinding, DualBindingMode mode = DualBindingMode.TwoWay)
        {
            var binding = new DualBinding(
                sourceBinding,
                new ObjectBinding(control, widgetPropertyName),
                mode
                );

            control.Bindings.Add(binding);
            return(binding);
        }
示例#3
0
		public static DualBinding Bind (this Widget widget, string widgetPropertyName, object source, string sourcePropertyName, DualBindingMode mode = DualBindingMode.TwoWay)
		{
			var binding = new DualBinding (
				source,
				sourcePropertyName,
				widget,
				widgetPropertyName,
				mode
			);
			widget.Bindings.Add (binding);
			return binding;
		}
示例#4
0
        /// <summary>
        /// Adds a new dual binding between the control and the specified object
        /// </summary>
        /// <param name="control">Control 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 Bind(this Control control, string propertyName, object source, string sourcePropertyName, DualBindingMode mode = DualBindingMode.TwoWay)
        {
            var binding = new DualBinding(
                source,
                sourcePropertyName,
                control,
                propertyName,
                mode
                );

            control.Bindings.Add(binding);
            return(binding);
        }
示例#5
0
        /// <summary>
        /// Adds a new dual binding between the widget and the specified object
        /// </summary>
        /// <param name="widget">Widget to add the binding to</param>
        /// <param name="widgetPropertyName">Property on the widget 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 Bind(this Widget widget, string widgetPropertyName, object source, string sourcePropertyName, DualBindingMode mode = DualBindingMode.TwoWay)
        {
            var binding = new DualBinding(
                source,
                sourcePropertyName,
                widget,
                widgetPropertyName,
                mode
                );

            widget.Bindings.Add(binding);
            return(binding);
        }
示例#6
0
        public static DualBinding Bind(this ObjectBinding controlBinding, DirectBinding valueBinding, DualBindingMode mode = DualBindingMode.TwoWay)
        {
            var binding = new DualBinding(
                valueBinding,
                controlBinding,
                mode
                );
            var control = controlBinding.DataItem as Control;

            if (control != null)
            {
                control.Bindings.Add(binding);
            }
            return(binding);
        }
示例#7
0
		/// <summary>
		/// Adds a new binding with the widget and the the widget's current data context 
		/// </summary>
		/// <remarks>
		/// This binds to a property of the <see cref="InstanceWidget.DataContext"/>, which will return the topmost value
		/// up the control hierarchy.  For example, you can set the DataContext of your form or panel, and then bind to properties
		/// of that context on any of the child controls such as a text box, etc.
		/// </remarks>
		/// <param name="widget">Widget to add the binding to</param>
		/// <param name="widgetPropertyName">Property on the widget to update</param>
		/// <param name="dataContextPropertyName">Property on the widget's <see cref="InstanceWidget.DataContext"/> to bind to the widget</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 Bind (this InstanceWidget widget, string widgetPropertyName, string dataContextPropertyName, DualBindingMode mode = DualBindingMode.TwoWay)
		{
			var contextBinding = new ObjectBinding(widget, "DataContext");
			var valueBinding = new ObjectBinding(contextBinding.DataValue, dataContextPropertyName);
			contextBinding.DataValueChanged += delegate {
				valueBinding.DataItem = contextBinding.DataValue;
			};
			var binding = new DualBinding (
				valueBinding,
				new ObjectBinding(widget, widgetPropertyName),
				mode
				);
			widget.Bindings.Add (contextBinding);
			widget.Bindings.Add (binding);
			return binding;
		}
示例#8
0
        /// <summary>
        /// Adds a new binding with the widget and the the widget's current data context
        /// </summary>
        /// <remarks>
        /// This binds to a property of the <see cref="InstanceWidget.DataContext"/>, which will return the topmost value
        /// up the control hierarchy.  For example, you can set the DataContext of your form or panel, and then bind to properties
        /// of that context on any of the child controls such as a text box, etc.
        /// </remarks>
        /// <param name="widget">Widget to add the binding to</param>
        /// <param name="widgetPropertyName">Property on the widget to update</param>
        /// <param name="dataContextPropertyName">Property on the widget's <see cref="InstanceWidget.DataContext"/> to bind to the widget</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 Bind(this InstanceWidget widget, string widgetPropertyName, string dataContextPropertyName, DualBindingMode mode = DualBindingMode.TwoWay)
        {
            var contextBinding = new ObjectBinding(widget, "DataContext");
            var valueBinding   = new ObjectBinding(contextBinding.DataValue, dataContextPropertyName);

            contextBinding.DataValueChanged += delegate {
                valueBinding.DataItem = contextBinding.DataValue;
            };
            var binding = new DualBinding(
                valueBinding,
                new ObjectBinding(widget, widgetPropertyName),
                mode
                );

            widget.Bindings.Add(contextBinding);
            widget.Bindings.Add(binding);
            return(binding);
        }
示例#9
0
        public static DualBinding Bind(this ObjectBinding controlBinding, IndirectBinding dataContextBinding, DualBindingMode mode = DualBindingMode.TwoWay, object defaultControlValue = null, object defaultContextValue = null)
        {
            var control = controlBinding.DataItem as Control;

            if (control == null)
            {
                throw new ArgumentOutOfRangeException("controlBinding", "Binding must be attached to a control");
            }
            var contextBinding = new ObjectBinding(control, new DelegateBinding <Control, object>(w => w.DataContext, null, (w, h) => w.DataContextChanged += h, (w, h) => w.DataContextChanged -= h));
            var valueBinding   = new ObjectBinding(control.DataContext, dataContextBinding)
            {
                GettingNullValue = defaultControlValue,
                SettingNullValue = defaultContextValue
            };
            DualBinding binding = Bind(controlBinding: controlBinding, valueBinding: valueBinding, mode: mode);

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