Remarks: This binding does not directly bind to an object - you must pass the object to get/set the value. The DirectBinding<T> differs in that it binds directly to an object. The IndirectBinding is useful when you want to use the same binding on multiple objects, such as when binding cells in a Grid. Typically one would use PropertyBinding<T> or ColumnBinding<T> which are ways to retrieve either a property value or column/index-based value.
Type parameters:
| T |
Methods
AddValueChangedHandler
#Adds a handler to trap when the value of this binding changes for the specified object
Remarks: This is used to wire up events (or other mechanisms) to detect if the value is changed for a particular object. This is typically used to fire the DirectBinding<T>.DataValueChanged event (which is wired up automatically)
Parameters:
| dataItem (object) | object to hook up the value changed event for |
| handler (EventHandler<EventArgs>) | handler for when the value of this binding changes for the specified object |
Returns: object to track the changed handler (must be passed to RemoveValueChangedHandler(object, EventHandler<EventArgs>) to remove)
AfterDelay
#Specifies that the binding should only respond to change events after a delay.
Remarks: This is useful if the property/delegate that is bound is expensive to retrieve the new value, for example to dynamically generate a bitmap based on the state of the model, etc. The
reset boolean allows you to ensure that the binding is updated periodically when false (default), or true to wait for the delay period after the last change event.Parameters:
| delay (double) | The delay, in seconds to wait after the value has changed before updating the binding. |
| reset (bool = false) | true to reset the delay every time the event is fired, false to trigger the change at least by the delay interval since the last time it was triggered |
Returns: A binding that will delay the change event
AfterDelay
#Specifies that the binding should only respond to change events after a delay.
Remarks: This is useful if the property/delegate that is bound is expensive to retrieve the new value, for example to dynamically generate a bitmap based on the state of the model, etc. The
reset boolean allows you to ensure that the binding is updated periodically when false (default), or true to wait for the delay period after the last change event.Parameters:
| delay (TimeSpan) | The delay time span to wait after the value has changed before updating the binding. |
| reset (bool = false) | true to reset the delay every time the event is fired, false to trigger the change at least by the delay interval since the last time it was triggered |
Returns: A binding that will delay the change event
CatchException
#Catches any exceptions when setting the value of the binding
CatchException<TException>
#public IndirectBinding<T> CatchException<TException>(Func<TException, bool> exceptionHandler = null)
Catches any exceptions of the specified
TException when setting the value of the binding.Child<TNewValue>
#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.Parameters:
| property (Expression<Func<T, TNewValue>>) | Property to bind to. |
Returns: The binding to the child property accessed through the current binding.
Example:Use this like so:
public class MyChild { public SomeChildProperty { get; set; } }
public class MyModel { public ChildObject { get; set; } }
Binding.Property((MyModel m) => m.ChildObject).Child(c => c.SomeChildProperty);
// or:
Binding.Property((MyModel m) => m.ChildObject.SomeChildProperty);Child<TNewValue>
#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.Parameters:
| binding (IndirectBinding<TNewValue>) | Binding to get the child value from this binding. |
Returns: The binding to the child property accessed through the current binding.
Example:Use this like so:
public class MyChild { public SomeChildProperty { get; set; } }
public class MyModel { public ChildObject { get; set; } }
Binding.Property((MyModel m) => m.ChildObject).Child(Binding.Property("SomeChildProperty"));Convert
#public IndirectBinding<object> Convert(IValueConverter converter, Type propertyType, object conveterParameter = null, CultureInfo culture = null)
Converts the binding using the specified
converter object.Parameters:
| converter (IValueConverter) | Converter object to use when converting to/from the value |
| propertyType (Type) | Type for the converter to convert to |
| conveterParameter (object = null) | Parameter to pass to the converter. |
| culture (CultureInfo = null) | Culture to use for conversion, null to use invariant culture. |
Returns: A new binding that will be converted using the specified IValueConverter.
public IndirectBinding<TValue> Convert<TValue>(Func<T, TValue> getValue, Action<T, TValue> setValue)
Converts this binding's value to another value using delegates.
Remarks: This differs from 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.
Parameters:
| 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. |
Returns: A new binding that will be converted using the specified delegates.
Convert<TValue>
#public IndirectBinding<TValue> Convert<TValue>(Func<T, TValue> toValue, Func<TValue, T> 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.
Convert<TValue>
#public IndirectBinding<TValue> Convert<TValue>(IValueConverter converter, object conveterParameter = null, CultureInfo culture = null)
Converts the binding using the specified
converter object.Parameters:
| converter (IValueConverter) | Converter object to use when converting to/from the value |
| conveterParameter (object = null) | Parameter to pass to the converter. |
| culture (CultureInfo = null) | Culture to use for conversion, null to use invariant culture. |
Returns: A new binding that will be converted using the specified IValueConverter.
EnumToString
#Converts the a binding to an enumeration to/from its string representation
Parameters:
| defaultValue (T = null) | Default if the value is not valid or empty. |
Returns: Binding to the string value of the enumeration.
GetValue
#Gets the value from the specified object using this binding
Remarks: When values are needed from this binding, this method will be called. Implementors of this binding would implement logic in InternalGetValue(object)
Parameters:
| dataItem (object) | object to retrieve the value from |
Returns: value from the specified object
Implements: GetValue
InternalGetValue
#Implements the logic to get the value from the specified object
Remarks: Implementors of this binding must implement this method to get the value from the specified object
Parameters:
| dataItem (object) | object to get the value from |
Returns: value from this binding of the specified object
InternalSetValue
#Implements the logic to set the value to the specified object
Parameters:
| dataItem (object) | object to set the value to |
| value (T) | value to set on the dataItem for this binding |
OfType<TValue>
#public IndirectBinding<TValue> OfType<TValue>(TValue defaultConvertedValue = default(TValue), T defaultValue = default(T))
Casts this binding value to another (compatible) type, or returns the default if the types do not match.
Parameters:
| defaultConvertedValue (TValue = null) | |
| defaultValue (T = null) |
inherited fromBinding
inherited fromBinding
RemoveValueChangedHandler
#public virtual void RemoveValueChangedHandler(object bindingReference, EventHandler<EventArgs> handler)
Removes the handler for the specified reference from AddValueChangedHandler(object, EventHandler<EventArgs>)
Parameters:
| bindingReference (object) | Reference from the call to AddValueChangedHandler(object, EventHandler<EventArgs>) |
| handler (EventHandler<EventArgs>) | Same handler that was set up during the AddValueChangedHandler(object, EventHandler<EventArgs>) call |
SetValue
#Sets the specified value to an object using this binding
Remarks: This is called to set the value to the object. Implementors of this binding woulc implement logic in InternalSetValue(object, T).
Parameters:
| dataItem (object) | object to set the value to |
| value (T) | value to set to the object |
Implements: SetValue
ToBool
#Converts this binding to return a nullable boolean binding
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.Parameters:
| trueValue (T) | Value when the binding is true. |
| falseValue (T) | Value when the binding is false. |
| nullValue (T) | Value when the binding is null. |
Returns: Boolean binding.
ToBool
#Converts this binding to return a nullable boolean binding
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.Parameters:
| trueValue (T) | Value when the binding is true. |
| falseValue (T) | Value when the binding is false. |
Returns: Boolean binding.
ToBool
#Converts this binding to return a nullable boolean binding
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.Parameters:
| trueValue (T) | Value when the binding is true. |
Returns: Boolean binding.
ToType<TType>
#public IndirectBinding<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.
Remarks: This has additional logic to deal with nullable types so they can be converted properly as well.
Parameters:
| 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. |
Returns: 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)
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
Implements: Unbind
Update
Updates the bound target object's value
Remarks: Typically the source would be your custom class and the destination would be a UI control, but this is not always the case.
Parameters:
| mode (BindingUpdateMode = BindingUpdateMode.Destination) | Direction of the update |
Implements: Update
Events
Changed
Event to handle after the value has been set using this binding
Changing
Event to handle when the value is being set using this binding
Remarks: This can be used to stop a value being updated based on custom logic