Class Binding
Represents a class for property binding. It provides automatic property update for supported objects.
public sealed class Binding : IBinding, IDisposable
- Inheritance
-
Binding
- Implements
- Inherited Members
- Extension Methods
Remarks
This binding implementation can dynamically change source objects and binding modes.
Constructors
Binding(IBindingTarget, IPropertyReference, IPropertyPath)
Initializes a new instance of the Binding class.
public Binding(IBindingTarget target, IPropertyReference targetProperty, IPropertyPath sourceProperty)
Parameters
targetIBindingTargetTarget object to bind.
targetPropertyIPropertyReferenceProperty of the target object to bind to.
sourcePropertyIPropertyPathProperty path of the source object to access.
Binding(IPropertyPath)
Initializes a new instance of the Binding class.
public Binding(IPropertyPath sourceProperty)
Parameters
sourcePropertyIPropertyPathProperty path of the source object to access.
Remarks
Note that this initializer makes incomplete binding that is not ready for work. You'll need to call Bind(IBinding) with the created instance to complete the binding.
Properties
ConverterParameters
Gets or sets the parameters for the value conversion.
public BindingConverterParameters? ConverterParameters { get; set; }
Property Value
Culture
Gets or sets the culture this binding formats values as text and parses text into values with, or null (the default) to use the configuration's.
public CultureInfo? Culture { get; set; }
Property Value
Remarks
While unset, the culture is looked up at each conversion, in this order:
- the Culture of the canvas the target element is attached to;
- the configuration that loaded the binding from markup, for a target that isn't attached yet;
- CurrentUICulture.
It also applies to the ConverterParameters converter when that has no culture of its own.
ElementName
Gets or sets the name of the UI element that should be used as the binding source.
public string? ElementName { get; set; }
Property Value
Error
Gets the failure that put this binding into its error state, or null when there is none.
public Exception? Error { get; }
Property Value
Remarks
For example the type converter's exception for text that doesn't parse, or the exception the source property's own setter threw. Exceptions wrapped in TargetInvocationException are unwrapped.
FallbackValue
Gets or sets the value that is set when the binding cannot return the value.
public object? FallbackValue { get; set; }
Property Value
HasError
Gets a value indicating whether the last write to the source failed.
public bool HasError { get; }
Property Value
Remarks
Writing to the source never throws for a bad value: the source keeps its previous value and this flag is set instead (see Error). It clears on the next successful write in either direction.
When the target is a UIElement, the element carries Invalid while any of its bindings has an error, so styles can show it.
IsEnabled
Gets or sets a value indicating whether the binding is enabled and listening to updates.
public bool IsEnabled { get; set; }
Property Value
Mode
Gets or sets a value defining the direction of the binding.
public BindingMode Mode { get; set; }
Property Value
Path
Gets the property path to the source object to get values from.
public IPropertyPath Path { get; }
Property Value
Source
Gets or sets the source object to access.
public object? Source { get; set; }
Property Value
Target
Gets the target object to set values to.
[MemberNotNull("target")]
public IBindingTarget Target { get; }
Property Value
TargetNullValue
Gets or sets the value of the target property that is set when the source returns null.
public object? TargetNullValue { get; set; }
Property Value
TargetProperty
Gets or sets the property of the target object to access.
public IPropertyReference TargetProperty { get; set; }
Property Value
UpdateSourceTrigger
Gets or sets a value defining target triggers to update source property.
public UpdateSourceTrigger UpdateSourceTrigger { get; set; }
Property Value
UpdateTargetTrigger
Gets or sets a value indicating when the binding refreshes its target from its source.
public UpdateTargetTrigger UpdateTargetTrigger { get; set; }
Property Value
Methods
DestroyBinding()
Unsubscribe from source and target objects.
public void DestroyBinding()
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
~Binding()
Finalizes an instance of the Binding class.
protected ~Binding()
UpdateSource()
Force update source object from target object.
public void UpdateSource()
UpdateTarget()
Force update target object from source object.
public void UpdateTarget()
Events
ErrorChanged
public event EventHandler? ErrorChanged