public class BindableBinding<T, TValue> : ObjectBinding<T, TValue>
Binding object to easily bind a property of a IBindable object, such as a Control.
Remarks: This provides control-specific binding, such as binding to a IBindable.DataContext. Any bindings created using this will also add to the IBindable.Bindings collection to keep its reference.
T where IBindable
TValue

Constructors

BindableBinding

#
public BindableBinding(T dataItem, Func<T, TValue> getValue, Action<T, TValue> setValue = null, Action<T, EventHandler<EventArgs>> addChangeEvent = null, Action<T, EventHandler<EventArgs>> removeChangeEvent = null)
Initializes a new instance of the ControlBinding<T, TValue> class.
dataItem (T)Data item to get/set the values from/to.
getValue (Func<T, TValue>)Delegate to get the value from the object.
setValue (Action<T, TValue> = null)Delegate to set the value to the object.
addChangeEvent (Action<T, EventHandler<EventArgs>> = null)Delegate to add the change event.
removeChangeEvent (Action<T, EventHandler<EventArgs>> = null)Delegate to remove the chang event.

BindableBinding

#
public BindableBinding(T dataItem, IndirectBinding<TValue> innerBinding)
Initializes a new instance of the ControlBinding<T, TValue> class.
dataItem (T)Control the binding is attached to.
innerBinding (IndirectBinding<TValue>)Inner binding.

Properties

DataItem

public T DataItem { get; set; }
Gets or sets the object to get/set the values using the ObjectBinding<T, TValue>.InnerBinding
inherited fromObjectBinding<T, TValue>

DataValue

public override TValue DataValue { get; set; }
Gets or sets the value of this binding on the bound object
inherited fromObjectBinding<T, TValue>

GetDataItem

public Func<T> GetDataItem { get; set; }
Gets or sets a delegate used to get the current ObjectBinding<T, TValue>.DataItem value instead of storing the value in this binding.
inherited fromObjectBinding<T, TValue>
Remarks: This is used so that all bindings using a DataContext will be updated with the correct value as soon as the DataContext is set. For example, if updating one binding would trigger the setter of a secondary binding that hasn't been updated with the new value yet it would inadvertently change the DataContext even though it is now actually null. Use the ObjectBinding<T, TValue>.TriggerDataValueChanged() method to specify that the value returned by this delegate has changed, which will cause the binding to update all of its dependants. Note if this is set, then it will always be used to retrieve the DataItem. If you set the DataItem directly, this will be set to null and will no longer be used..
The delegate used to get the current data item

GettingNullValue

public TValue GettingNullValue { get; set; }
Gets or sets the default value to use when getting the value for this binding when the ObjectBinding<T, TValue>.DataItem or property value is null
inherited fromObjectBinding<T, TValue>

SettingNullValue

public TValue SettingNullValue { get; set; }
Gets or sets the default value to use when setting the value for this binding when input value is null
inherited fromObjectBinding<T, TValue>

Methods

Bind

#
public override DualBinding<TValue> Bind(DirectBinding<TValue> sourceBinding, DualBindingMode mode = DualBindingMode.TwoWay)
Binds the specified sourceBinding to this binding.
Remarks: This creates a DualBinding<TValue> between the specified sourceBinding and this binding. The binding is added to the IBindable.Bindings collection.
sourceBinding (DirectBinding<TValue>)Source binding to bind from.
mode (DualBindingMode = DualBindingMode.TwoWay)Dual binding mode.

Bind

public DualBinding<TValue> Bind(Func<TValue> getValue, Action<TValue> setValue = null, Action<EventHandler<EventArgs>> addChangeEvent = null, Action<EventHandler<EventArgs>> removeChangeEvent = null, DualBindingMode mode = DualBindingMode.TwoWay)
Creates a new dual binding using a DelegateBinding<TValue> with the specified delegates and this binding.
inherited fromObjectBinding<T, TValue>
Remarks: This creates a DualBinding<TValue> between a new DelegateBinding<TValue> and this binding. This does not require an object instance for the delegates to get/set the value. You must keep a reference to the binding to unbind when finished.
getValue (Func<TValue>)Delegate to get the value.
setValue (Action<TValue> = null)Delegate to set the value when changed.
addChangeEvent (Action<EventHandler<EventArgs>> = null)Delegate to add a change event when the value changes.
removeChangeEvent (Action<EventHandler<EventArgs>> = null)Delegate to remove the change event.
mode (DualBindingMode = DualBindingMode.TwoWay)Dual binding mode.

Bind

public DualBinding<TValue> Bind(object objectValue, string propertyName, DualBindingMode mode = DualBindingMode.TwoWay)
Creates a binding to the propertyName of the specified objectValue.
inherited fromObjectBinding<T, TValue>
Remarks: This is a shortcut to using the PropertyBinding<TValue>. This has the advantage of registering automatically to INotifyPropertyChanged or to an event named after the property with a "Changed" suffix.
objectValue (object)Object to bind to.
propertyName (string)Name of the property to bind to on the objectValue.
mode (DualBindingMode = DualBindingMode.TwoWay)Direction of the binding.

Bind<TObject>

public DualBinding<TValue> Bind<TObject>(TObject objectValue, Expression<Func<TObject, TValue>> propertyExpression, DualBindingMode mode = DualBindingMode.TwoWay)
Creates a binding to the specified objectValue with the specified propertyExpression.
inherited fromObjectBinding<T, TValue>
Remarks: This has the advantage of registering automatically to INotifyPropertyChanged or to an event named after the property with a "Changed" suffix, if the expression is a property. When the expression does not evaluate to a property, it will not be able to bind to the changed events and will use the expression as a delegate directly.
objectValue (TObject)Object to bind to.
propertyExpression (Expression<Func<TObject, TValue>>)Expression for a property of the objectValue, or a non-property expression with no change event binding.
mode (DualBindingMode = DualBindingMode.TwoWay)Direction of the binding
The binding between the data context and this binding

Bind<TObject>

public DualBinding<TValue> Bind<TObject>(TObject objectValue, IndirectBinding<TValue> objectBinding, DualBindingMode mode = DualBindingMode.TwoWay)
Creates a new dual binding between the specified objectBinding and this binding.
inherited fromObjectBinding<T, TValue>
objectValue (TObject)Object to get/set the values from/to.
objectBinding (IndirectBinding<TValue>)Indirect binding to get/set the values from the objectValue.
mode (DualBindingMode = DualBindingMode.TwoWay)Dual binding mode.

BindDataContext

#
public DualBinding<TValue> BindDataContext(IndirectBinding<TValue> dataContextBinding, DualBindingMode mode = DualBindingMode.TwoWay, TValue defaultControlValue = default(TValue), TValue defaultContextValue = default(TValue))
Binds to an object's IBindable.DataContext using the specified dataContextBinding.
Remarks: This creates a DualBinding<TValue> between a binding to the specified 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 IBindable.Bindings collection.
dataContextBinding (IndirectBinding<TValue>)Binding to get/set values from/to the control's data context.
mode (DualBindingMode = DualBindingMode.TwoWay)Dual binding mode.
defaultControlValue (TValue = null)Default control value.
defaultContextValue (TValue = null)Default context value.
A new dual binding that binds the dataContextBinding to this control binding.

BindDataContext

#
public DualBinding<TValue> BindDataContext(string propertyName, DualBindingMode mode = DualBindingMode.TwoWay)
Binds to the specified propertyName of the current data context.
Remarks: This is a shortcut to using the PropertyBinding<TValue>. This has the advantage of registering automatically to INotifyPropertyChanged or to an event named after the property with a "Changed" suffix.
propertyName (string)Name of the property on the data context to bind to.
mode (DualBindingMode = DualBindingMode.TwoWay)Direction of the binding.
The binding between the data context and this binding.

BindDataContext<TObject>

#
public DualBinding<TValue> BindDataContext<TObject>(Expression<Func<TObject, TValue>> propertyExpression, DualBindingMode mode = DualBindingMode.TwoWay)
Binds to a specified property of the control's current data context.
Remarks: This has the advantage of registering automatically to INotifyPropertyChanged or to an event named after the property with a "Changed" suffix, if the expression is a property. When the expression does not evaluate to a property, it will not be able to bind to the changed events and will use the expression as a delegate directly.
propertyExpression (Expression<Func<TObject, TValue>>)Expression for a property of the data context, or a non-property expression with no change event binding.
mode (DualBindingMode = DualBindingMode.TwoWay)Direction of the binding
The binding between the data context and this binding

BindDataContext<TObject>

#
public DualBinding<TValue> BindDataContext<TObject>(Func<TObject, TValue> getValue, Action<TObject, TValue> setValue, Action<TObject, EventHandler<EventArgs>> addChangeEvent = null, Action<TObject, EventHandler<EventArgs>> removeChangeEvent = null, DualBindingMode mode = DualBindingMode.TwoWay, TValue defaultGetValue = default(TValue), TValue defaultSetValue = default(TValue))
Binds to a control's IBindable.DataContext using delegates to get/set the value.
Remarks: This is a shortcut to use the DelegateBinding<T, TValue> to bind to a control's IBindable.DataContext property. When the data context type is TValue, then the delegates will be called to get/set the value. Otherwise, if the data context is null or a different type, the defaultGetValue will be used.
getValue (Func<TObject, TValue>)Delegate to get the value from the data context.
setValue (Action<TObject, TValue>)Delegate to set the value to the data context when changed.
addChangeEvent (Action<TObject, EventHandler<EventArgs>> = null)Delegate to add a change event on the data context.
removeChangeEvent (Action<TObject, EventHandler<EventArgs>> = null)Delegate to remove the change event from the data context.
mode (DualBindingMode = DualBindingMode.TwoWay)Dual binding mode.
defaultGetValue (TValue = null)Default get value.
defaultSetValue (TValue = null)Default set value.
A new dual binding that binds the control to this object binding.

Cast<TNewValue>

#
public BindableBinding<T, TNewValue> Cast<TNewValue>()
Casts this binding value to another (compatible) type.

CatchException

#
public BindableBinding<T, TValue> CatchException(Func<Exception, bool> exceptionHandler = null)
Catches any exceptions when setting the value of the binding
exceptionHandler (Func<Exception, bool> = null)Handler to call when setting the value, regardless of whether an exception occurs. Return true when the exception is handled, false to throw an exception.
The binding that catches any exception.

CatchException<TException>

#
public BindableBinding<T, TValue> CatchException<TException>(Func<TException, bool> exceptionHandler = null)
Catches any exceptions of the specified TException when setting the value of the binding.
exceptionHandler (Func<TException, bool> = null)Handler to call when setting the value, regardless of whether an exception occurs. Return true when the exception is handled, false to throw an exception.
The binding that catches the specified exception.

Child<TNewValue>

#
public BindableBinding<T, TNewValue> Child<TNewValue>(Expression<Func<T, TNewValue>> property)
Binds to the specified child property expression.
Remarks: This can be used to bind to properties of child objects of your view model, for example
model.SomeProperty.ChildProperty
. This will automatically look up the changed event either by a [Property]Changed event or INotifyPropertyChanged implementation for each object in the heirarchy. Note that you only really need to use this when you have an existing binding that you cannot change. See Binding.Property<T, TValue>(Expression<Func<T, TValue>>) for an example of how to bind to child property values more directly.
property (Expression<Func<T, TNewValue>>)Property to bind to.
The binding to the child property accessed through the current binding.
Use this like so:
public class MyChild { public SomeChildProperty { get; set; } }
public class MyModel { public ChildObject { get; set; } }

var model = new MyModel();
Binding.Property(model, (MyModel m) => m.ChildObject).Child(c => c.SomeChildProperty);

Child<TNewValue>

#
public BindableBinding<T, TNewValue> Child<TNewValue>(IndirectBinding<TNewValue> binding)
Binds to the specified child binding of this binding.
Remarks: This can be used to bind to child objects of your view model, for example
model.SomeProperty.ChildProperty
.
binding (IndirectBinding<TNewValue>)Binding to get the child value from this binding.
The binding to the child property accessed through the current binding.
Use this like so:
public class MyChild { public SomeChildProperty { get; set; } }
public class MyModel { public ChildObject { get; set; } }

var model = new MyModel();
Binding.Property(model, (MyModel m) => m.ChildObject).Child(Binding.Property("SomeChildProperty"));

Child<TValue>

public DirectBinding<TValue> Child<TValue>(Expression<Func<T, TValue>> property)
Binds to the specified child property expression.
inherited fromDirectBinding<T>
Remarks: This can be used to bind to properties of child objects of your view model, for example
model.SomeProperty.ChildProperty
. This will automatically look up the changed event either by a [Property]Changed event or INotifyPropertyChanged implementation for each object in the heirarchy. Note that you only really need to use this when you have an existing binding that you cannot change. See Binding.Property<T, TValue>(Expression<Func<T, TValue>>) for an example of how to bind to child property values more directly.
property (Expression<Func<T, TValue>>)Property to bind to.
The binding to the child property accessed through the current binding.
Use this like so:
public class MyChild { public SomeChildProperty { get; set; } }
public class MyModel { public ChildObject { get; set; } }

var model = new MyModel();
Binding.Property(model, (MyModel m) => m.ChildObject).Child(c => c.SomeChildProperty);

Child<TValue>

public DirectBinding<TValue> Child<TValue>(IndirectBinding<TValue> binding)
Binds to the specified child binding of this binding.
inherited fromDirectBinding<T>
Remarks: This can be used to bind to child objects of your view model, for example
model.SomeProperty.ChildProperty
.
binding (IndirectBinding<TValue>)Binding to get the child value from this binding.
The binding to the child property accessed through the current binding.
Use this like so:
public class MyChild { public SomeChildProperty { get; set; } }
public class MyModel { public ChildObject { get; set; } }

var model = new MyModel();
Binding.Property(model, (MyModel m) => m.ChildObject).Child(Binding.Property("SomeChildProperty"));

Convert<TNewValue>

#
public BindableBinding<T, TNewValue> Convert<TNewValue>(Func<TValue, TNewValue> toValue, Func<TNewValue, TValue> fromValue = null)
Converts this binding's value to another value using delegates.
Remarks: This is useful when you want to cast one binding to another, perform logic when getting/setting a value from a particular binding, or get/set a preoperty of the value.
toValue (Func<TValue, TNewValue>)Delegate to convert to the new value type.
fromValue (Func<TNewValue, TValue> = null)Delegate to convert from the value to the original binding's type.

Convert<TValue>

public DirectBinding<TValue> Convert<TValue>(Func<T, TValue> getValue, Action<T, TValue> setValue)
Converts this binding's value to another value using delegates.
inherited fromDirectBinding<T>
Remarks: This differs from DirectBinding<T>.Convert<TValue>(Func<T, TValue>, Func<TValue, T>) in that it allows the set value delegate to have access to the original parent value, which can be useful when needing to call a method of the parent binding instead of converting the value directly, or performing other logic.
getValue (Func<T, TValue>)Delegate to get the value from the original binding's type.
setValue (Action<T, TValue>)Delegate to set the value to the original binding's type.
A new binding with the specified TValue type.

Convert<TValue>

public DirectBinding<TValue> Convert<TValue>(Func<T, TValue> toValue, Func<TValue, T> fromValue = null)
Converts this binding's value to another value using delegates.
inherited fromDirectBinding<T>
Remarks: This is useful when you want to cast one binding to another, perform logic when getting/setting a value from a particular binding, or get/set a preoperty of the value.
toValue (Func<T, TValue>)Delegate to convert to the new value type.
fromValue (Func<TValue, T> = null)Delegate to convert from the value to the original binding's type.
A new binding with the specified TValue type.

Convert<TValue>

public DirectBinding<TValue> Convert<TValue>(IValueConverter converter, object conveterParameter = null, CultureInfo culture = null)
Converts this binding's value to another value using an IValueConverter.
inherited fromDirectBinding<T>
converter (IValueConverter)The value converter to use.
conveterParameter (object = null)An optional parameter to pass to the converter.
culture (CultureInfo = null)An optional culture to use for the conversion.
A new binding with the specified TValue type.

HandleEvent

protected override void HandleEvent(string id)
Hooks up the late bound events for this object
inherited fromObjectBinding<T, TValue>

OnDataValueChanged

protected virtual void OnDataValueChanged(EventArgs e)
inherited fromDirectBinding<T>
Remarks: Implementors of this class should call this method when the value changes on the bound object. Make sure to also override the HandleEvent and RemoveEvent methods to hook up/remove any event bindings you need on the bound object.
e (EventArgs)

ToBool

public DirectBinding<bool?> ToBool(T trueValue, T falseValue, T nullValue)
Converts this binding to return a nullable boolean binding
inherited fromDirectBinding<T>
Remarks: This is useful when converting a binding to be used for a checkbox's Checked binding for example. When the binding's value matches the trueValue, it will return true.
trueValue (T)Value when the binding is true.
falseValue (T)Value when the binding is false.
nullValue (T)Value when the binding is null.
Boolean binding.

ToBool

public DirectBinding<bool?> ToBool(T trueValue, T falseValue)
Converts this binding to return a nullable boolean binding
inherited fromDirectBinding<T>
Remarks: This is useful when converting a binding to be used for a checkbox's Checked binding for example. When the binding's value matches the trueValue, it will return true.
trueValue (T)Value when the binding is true.
falseValue (T)Value when the binding is false or null.
Boolean binding.

ToBool

public DirectBinding<bool?> ToBool(T trueValue)
Converts this binding to return a nullable boolean binding
inherited fromDirectBinding<T>
Remarks: This is useful when converting a binding to be used for a checkbox's Checked binding for example. When the binding's value matches the trueValue, it will return true.
trueValue (T)Value when the binding is true, false, or null.
Boolean binding.

ToString

public override string ToString()
Returns a String that represents the current ObjectBinding.
inherited fromObjectBinding<T, TValue>

ToType<TType>

public DirectBinding<TType> ToType<TType>(Func<T, TType> invalidGetValue = null, Func<TType, T> invalidSetValue = null)
Uses System.Convert.ChangeType to change the value of the binding to the specified type.
inherited fromDirectBinding<T>
Remarks: This has additional logic to deal with nullable types so they can be converted properly as well.
invalidGetValue (Func<T, TType> = null)Delegate to get a value when it cannot be converted to the specified TType. When null, an exception will be thrown when the value cannot be converted.
invalidSetValue (Func<TType, T> = null)Delegate to set a value when it cannot be converted from the specified TType. When null, an exception will be thrown when the value cannot be converted.
A binding of the new type that is a converted version of this binding

TriggerDataValueChanged

public void TriggerDataValueChanged()
inherited fromObjectBinding<T, TValue>
Remarks: When using the ObjectBinding<T, TValue>.GetDataItem delegate to retrieve the value of the DataItem, you can call this method to trigger that its value has been changed.

Update

public virtual void Update(BindingUpdateMode mode = BindingUpdateMode.Destination)
Updates the bound target object's value
inherited fromBinding
Remarks: Typically the source would be your custom class and the destination would be a UI control, but this is not always the case.
mode (BindingUpdateMode = BindingUpdateMode.Destination)Direction of the update
Update

Events

Changing

public event EventHandler<BindingChangingEventArgs> Changing
Event to handle when the value is being set using this binding
inherited fromBinding
Remarks: This can be used to stop a value being updated based on custom logic