PropertyBinding<T>
IndirectBinding<1>BindingIndirect binding to get/set values using a property of a specified object
Remarks: This is used when you are binding to a particular property of an object. This can be used to get/set values from any object. If you want to bind to a particular object directly, use the ObjectBinding<T> with this class as its inner binding.
Type parameters:
| T |
Constructors
Properties
Methods
AddValueChangedHandler
#Wires an event handler to fire when the property of the dataItem is changed
Parameters:
| dataItem (object) | object to detect changes on |
| handler (EventHandler<EventArgs>) | handler to fire when the property changes on the specified dataItem |
Returns: binding reference used to track the event hookup, to pass to RemoveValueChangedHandler(object, EventHandler<EventArgs>) when removing the handler
Overrides: IndirectBinding<T>.AddValueChangedHandler
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
Cast<TValue>
Casts this binding value to another (compatible) type.
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.
Convert<TValue>
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 IndirectBinding<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.
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 IndirectBinding<T>.InternalGetValue(object)
Parameters:
| dataItem (object) | object to retrieve the value from |
Returns: value from the specified object
Implements: GetValue
HasProperty
#Determines whether the dataItem contains the property this binding is bound to.
Parameters:
| dataItem (object) | Data item to find the property. |
Returns:
true if the dataItem instance has the correct property to bind to, otherwise, false.InternalGetValue
#Implements the logic to get the value from the specified object
Parameters:
| dataItem (object) | object to get the value from |
Returns: value of the property from the specified dataItem object
Overrides: IndirectBinding<T>.InternalGetValue
InternalSetValue
#Implements the logic to set the value on the specified object
Parameters:
| dataItem (object) | object to set the value to |
| value (T) | value to set to the property of the specified dataItem object |
Overrides: IndirectBinding<T>.InternalSetValue
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 override 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 |
Overrides: IndirectBinding<T>.RemoveValueChangedHandler
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 IndirectBinding<T>.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.
ToString
#Returns a String that represents the current PropertyBinding.
Returns: A String that represents the current PropertyBinding.
Overrides: Object.ToString
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