Binding

References
public abstract class Binding : IBinding
Base class for binding between a value and another
Remarks: This is the base of any type of binding. Some bindings may only be used to get/set a single value (e.g. IndirectBinding<T>), whereas the DualBinding<T> can link two objects' values together

Methods

AddPropertyEvent

#
public static void AddPropertyEvent(object obj, string propertyName, EventHandler<EventArgs> eh)
Adds an event handler for a specified propertyName of a INotifyPropertyChanged object.
Remarks: This can be used to translate an INotifyPropertyChanged event for a particular property to a single event. Typically, this would be used when creating a DelegateBinding<T, TValue> to attach to property notified events instead of singular events.
obj (object)INotifyPropertyChanged object to attach the event handler to
propertyName (string)Name of the property to trigger the changed event.
eh (EventHandler<EventArgs>)Event handler delegate to trigger when the specified property changes

AddPropertyEvent<T, TProperty>

#
public static void AddPropertyEvent<T, TProperty>(T obj, Expression<Func<T, TProperty>> propertyExpression, EventHandler<EventArgs> eh)
Adds an event handler for a specified propertyExpression of a INotifyPropertyChanged object.
Remarks: This can be used to translate an INotifyPropertyChanged event for a particular property to a single event. Typically, this would be used when creating a DelegateBinding<T, TValue> to attach to property notified events instead of singular events.
obj (T)INotifyPropertyChanged object to attach the event handler to
propertyExpression (Expression<Func<T, TProperty>>)Expression to the property to trigger the changed event.
eh (EventHandler<EventArgs>)Event handler delegate to trigger when the specified property changes

Delegate<TValue>

#
public static DirectBinding<TValue> Delegate<TValue>(Func<TValue> getValue, Action<TValue> setValue = null, Action<EventHandler<EventArgs>> addChangeEvent = null, Action<EventHandler<EventArgs>> removeChangeEvent = null)
Creates a new direct delegate binding.
getValue (Func<TValue>)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.

Delegate<T, TValue>

#
public static IndirectBinding<TValue> Delegate<T, TValue>(Func<T, TValue> getValue, Action<T, TValue> setValue = null, Action<T, EventHandler<EventArgs>> addChangeEvent = null, Action<T, EventHandler<EventArgs>> removeChangeEvent = null, TValue defaultGetValue = default(TValue), TValue defaultSetValue = default(TValue))
Creates a new indirect delegate binding.
getValue (Func<T, TValue>)Delegate to get the value for the binding.
setValue (Action<T, TValue> = null)Delegate to set the value for the binding.
addChangeEvent (Action<T, EventHandler<EventArgs>> = null)Delegate to register the change event, when needed by the consumer of this binding.
removeChangeEvent (Action<T, EventHandler<EventArgs>> = null)Delegate to remove the change event.
defaultGetValue (TValue = null)Default get value, when the object instance is null.
defaultSetValue (TValue = null)Default set value, when the incoming value is null.

ExecuteCommand

#
public static void ExecuteCommand(object dataContext, IndirectBinding<ICommand> commandBinding, object parameter = null)
Executes a command retrieved using the specified commandBinding from the dataContext.
Remarks: This helper method is useful for binding general events to fire an ICommand that is in your view model. The command will only be executed if its ICommand.CanExecute(object) returns true. Most controls (e.g. Button) have a special Command parameter that can be set instead, which takes into account the enabled state of the command and will enable/disable the control automatically.
dataContext (object)Data context object to get the ICommand via the commandBinding.
commandBinding (IndirectBinding<ICommand>)Binding to get the ICommand from the data context
parameter (object = null)Parameter to pass to the command when executing or checking if it can execute.
This example will fire the MyModel.MyCommand when the mouse is down on the specified panel. The MyModel instance is based off the panel's current DataContext.
var panel = new Panel();
panel.MouseDown += (sender, e) => Binding.ExecuteCommand(panel.DataContext, Binding.Property((MyModel m) => m.MyCommand));

ExecuteCommand<T>

#
public static void ExecuteCommand<T>(object dataContext, Expression<Func<T, ICommand>> commandExpression, object parameter = null)
Executes a command retrieved using a property commandExpression from the dataContext.
Remarks: This helper method is useful for binding general events to fire an ICommand that is in your view model. The command will only be executed if its ICommand.CanExecute(object) returns true. Most controls (e.g. Button) have a special Command parameter that can be set instead, which takes into account the enabled state of the command and will enable/disable the control automatically.
dataContext (object)Data context object to get the ICommand via the commandBinding.
commandExpression (Expression<Func<T, ICommand>>)Property expression to get the ICommand from the data context
parameter (object = null)Parameter to pass to the command when executing or checking if it can execute.
This example will fire the MyModel.MyCommand when the mouse is down on the specified panel. The MyModel instance is based off the panel's current DataContext.
var panel = new Panel();
panel.MouseDown += (sender, e) => Binding.ExecuteCommand(panel.DataContext, (MyModel m) => m.MyCommand);

HandleEvent

#
protected virtual void HandleEvent(string id)
Called to handle an event for this binding

Property<T, TValue>

#
public static DirectBinding<TValue> Property<T, TValue>(T model, Expression<Func<T, TValue>> propertyExpression)
Creates a new direct property binding to the specified model object.
model (T)Model object to bind to.
propertyExpression (Expression<Func<T, TValue>>)Expression to the property of the model object.

Property<T, TValue>

#
public static IndirectBinding<TValue> Property<T, TValue>(Expression<Func<T, TValue>> propertyExpression)
Creates a new indirect property binding using the specified propertyExpression.
Remarks: This supports single and multiple levels of property accessors in the model.
propertyExpression (Expression<Func<T, TValue>>)Expression of the property to bind to.
Use this like so:
public class MyChild { public SomeChildProperty { get; set; } }
public class MyModel { 
	public ChildObject { get; set; } 
	public int IntProperty { get; set; } 
}

// direct property binding
Binding.Property((MyModel m) => m.IntProperty);

// bind to a property of a child object of the view model
Binding.Property((MyModel m) => m.ChildObject.SomeChildProperty);

Property<TValue>

#
public static IndirectBinding<TValue> Property<TValue>(string propertyName, bool ignoreCase)
Creates a new indirect property binding using the specified propertyName.
Remarks: This supports single and multiple levels of property accessors in the model.
propertyName (string)Name of the property to bind to.
ignoreCase (bool)True to ignore case of the property name, false to match the property name exactly.
Use this like so:
public class MyChild { public SomeChildProperty { get; set; } }
public class MyModel { 
	public ChildObject { get; set; } 
	public int IntProperty { get; set; } 
}

// direct property binding
Binding.Property("IntProperty");

// bind to a property of a child object of the view model
Binding.Property("ChildObject.SomeChildProperty");

Property<TValue>

#
public static IndirectBinding<TValue> Property<TValue>(string propertyName)
Creates a new indirect property binding using the specified propertyName.
Remarks: This supports single and multiple levels of property accessors in the model.
propertyName (string)Name of the property to bind to.
Use this like so:
public class MyChild { public SomeChildProperty { get; set; } }
public class MyModel { 
	public ChildObject { get; set; } 
	public int IntProperty { get; set; } 
}

// direct property binding
Binding.Property("IntProperty");

// bind to a property of a child object of the view model
Binding.Property("ChildObject.SomeChildProperty");

RemoveEvent

#
protected virtual void RemoveEvent(string id)
Called to remove an event for this binding

RemovePropertyEvent

#
public static void RemovePropertyEvent(object obj, EventHandler<EventArgs> eh)
Removes an event handler previously attached with the AddPropertyEvent method.
Remarks: Note that this will unsubscribe from all property handlers that point to the same delegate specified by eh. Use RemovePropertyEvent(object, string, EventHandler<EventArgs>) to only unsubscribe for a single property.
obj (object)Object the event is subscribed to
eh (EventHandler<EventArgs>)Event handler delegate to remove

RemovePropertyEvent

#Since v2.9
public static void RemovePropertyEvent(object obj, string propertyName, EventHandler<EventArgs> eh)
Removes an event handler previously attached with the AddPropertyEvent method.
obj (object)INotifyPropertyChanged object to unsubscribe from
propertyName (string)Name of the property to remove the event handler for
eh (EventHandler<EventArgs>)Event handler delegate to remove

RemovePropertyEvent<T, TProperty>

#Since v2.9
public static void RemovePropertyEvent<T, TProperty>(T obj, Expression<Func<T, TProperty>> propertyExpression, EventHandler<EventArgs> eh)
Removes an event handler previously attached with the AddPropertyEvent method.
obj (T)INotifyPropertyChanged object to unsubscribe from
propertyExpression (Expression<Func<T, TProperty>>)Expression for the property to remove the event handler for
eh (EventHandler<EventArgs>)Event handler delegate to remove

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
Unbind

Update

#
public virtual void Update(BindingUpdateMode mode = BindingUpdateMode.Destination)
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.
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
Remarks: This can be used to stop a value being updated based on custom logic