public static DualBinding Bind(this Control control, IndirectBinding controlBinding, object objectValue, IndirectBinding objectBinding, DualBindingMode mode = DualBindingMode.TwoWay, object defaultControlValue = null, object defaultContextValue = null) { var valueBinding = new ObjectBinding(objectValue, objectBinding) { SettingNullValue = defaultContextValue, GettingNullValue = defaultControlValue }; return(Bind(control, controlBinding, valueBinding, mode)); }
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; }
public DualBinding (ObjectBinding source, ObjectBinding destination, DualBindingMode mode = DualBindingMode.TwoWay) { this.Source = source; this.Destination = destination; if (mode == DualBindingMode.OneWay || mode == DualBindingMode.TwoWay) source.DataValueChanged += HandleSourceChanged; if (mode == DualBindingMode.OneWayToSource || mode == DualBindingMode.TwoWay) destination.DataValueChanged += HandleDestinationChanged; // set initial value this.SetDestination (); }
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); }
/// <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; }
/// <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); }
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); }
public DualBinding Bind <TObject>(TObject objectValue, DelegateBinding <TObject, TValue> objectBinding, DualBindingMode mode = DualBindingMode.TwoWay) { var valueBinding = new ObjectBinding(objectValue, objectBinding); return(BindingExtensions.Bind(controlBinding: this, valueBinding: valueBinding, mode: mode)); }