DelegateBinding<TValue>

DirectBinding<1>Binding
public class DelegateBinding<TValue> : DirectBinding<TValue>
Direct delegate binding.
Remarks: This is a direct binding, in that the get/set delegates can get/set the value directly without any associated object instance. This is used when binding directly to a property or when an object instance isn't needed to get/set a value.
TValue

Constructors

DelegateBinding

#
public DelegateBinding(Func<TValue> getValue = null, Action<TValue> setValue = null, Action<EventHandler<EventArgs>> addChangeEvent = null, Action<EventHandler<EventArgs>> removeChangeEvent = null)
Initializes a new instance of the DelegateBinding<TValue> class with the specified delegates.
getValue (Func<TValue> = null)Delegate to get the value for the binding.
setValue (Action<TValue> = null)Delegate to set the value for the binding.
addChangeEvent (Action<EventHandler<EventArgs>> = null)Delegate to register the change event, when needed by the consumer of this binding.
removeChangeEvent (Action<EventHandler<EventArgs>> = null)Delegate to remove the change event.

Properties

AddChangeEvent

#
public Action<EventHandler<EventArgs>> AddChangeEvent { get; set; }
Gets or sets the delegate to register the change event, when needed by the consumer of this binding.

DataValue

#
public override TValue DataValue { get; set; }
Gets or sets the value of this binding

GetValue

#
public Func<TValue> GetValue { get; set; }
Gets or sets the delegate to get the value for this binding.

RemoveChangeEvent

#
public Action<EventHandler<EventArgs>> RemoveChangeEvent { get; set; }
Gets or sets the delegate to remove the change event.

SetValue

#
public Action<TValue> SetValue { get; set; }
Gets or sets the delegate to set the value for this binding.

Methods

CatchException

public DirectBinding<T> CatchException(Func<Exception, bool> exceptionHandler = null)
Catches any exceptions when setting the value of the binding
inherited fromDirectBinding<T>
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 DirectBinding<T> CatchException<TException>(Func<TException, bool> exceptionHandler = null)
Catches any exceptions of the specified TException when setting the value of the binding.
inherited fromDirectBinding<T>
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<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<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

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)

RemoveEvent

#
protected override void RemoveEvent(string id)
Removes the late bound events for this object

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.

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

Unbind

public virtual void Unbind()
Unbind this from the target object(s)
inherited fromBinding
Remarks: Typically a binding may handle an event for when the target object(s) property values are changed. This is called to unbind the binding from the objects so that they can be garbage collected
Unbind

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