BindingValue<T>)BindingValue<T>)Optional<T> as a Missing-Value PrimitiveBindingNotification)BindingChainException)BindingOperations.DoNothingType and No-Update SemanticsInstancedBinding for Dynamic PipelinesIndexerDescriptor and Property Indexer BindingPrimary APIs:
BindingValue<T>BindingValueTypeBindingNotificationBindingErrorTypeOptional<T>BindingChainExceptionInstancedBindingIBindingBindingOperationsBindingOperations.DoNothingTypeBindingExpressionBaseIndexerDescriptorCompatibility-sensitive APIs in this space:
IBinding.Initiate(...) (obsolete in 11.3.12)BindingOperations.Apply(...) (obsolete in 11.3.12)Reference source files:
src/Avalonia.Base/Data/BindingValue.cssrc/Avalonia.Base/Data/BindingNotification.cssrc/Avalonia.Base/Data/Optional.cssrc/Avalonia.Base/Data/BindingChainException.cssrc/Avalonia.Base/Data/InstancedBinding.cssrc/Avalonia.Base/Data/IBinding.cssrc/Avalonia.Base/Data/BindingOperations.cssrc/Avalonia.Base/Data/BindingExpressionBase.cssrc/Avalonia.Base/Data/IndexerDescriptor.cssrc/Avalonia.Base/AvaloniaObject.cssrc/Avalonia.Base/AvaloniaObjectExtensions.csBindingValue<T>)BindingValue<T> is the typed transport used in binding pipelines. It carries both value and state.
Core states (BindingValueType):
ValueUnsetValueDoNothingBindingError / BindingErrorWithFallbackDataValidationError / DataValidationErrorWithFallbackUseful members:
Type, HasValue, HasError, Value, ErrorUnset, DoNothingBindingError(...), DataValidationError(...)WithValue(...)GetValueOrDefault(...)ToOptional()Design implication:
GetBindingObservable(...).BindingValue<T>)Construction and conversion APIs:
BindingValue(T value)implicit operator BindingValue<T>(T value)implicit operator BindingValue<T>(Optional<T> optional)Practical semantics:
T conversion creates a BindingValueType.Value state,Optional<T> conversion preserves HasValue semantics (default(Optional<T>) maps to unset),Example:
BindingValue<int> fromCtor = new BindingValue<int>(42);
BindingValue<int> fromImplicitValue = 42;
Optional<int> missing = default;
BindingValue<int> fromOptional = missing; // maps to unset semantics
Optional<T> as a Missing-Value PrimitiveOptional<T> is a small two-state value (HasValue / missing) used by property/binding internals.
Useful members:
HasValueValueGetValueOrDefault(...)EmptyToObject()operator Optional<T>OptionalExtensions.Cast<T>(...)Use:
null for reference types,Creation forms:
new Optional<T>(value)operator Optional<T> from plain TInterop helper:
ToObject() converts Optional<T> to Optional<object?> for untyped bridges.OptionalExtensions.Cast<T>(...) rehydrates typed optional values from untyped optional payloads.BindingNotification)BindingNotification is the untyped carrier for:
Error, ErrorType),Value, HasValue).Useful APIs:
ExtractValue(...)UpdateValue(...)ExtractError(...)AddError(...)BindingNotification.NullUse it when integrating untyped binding edges, custom adapters, or diagnostics surfaces.
Bridge APIs:
BindingValue<T>.ToUntyped()BindingValue<T>.FromUntyped(...)Special-value mapping is stable:
AvaloniaProperty.UnsetValue <-> BindingValue<T>.UnsetBindingOperations.DoNothing <-> BindingValue<T>.DoNothingBindingNotification <-> BindingError* / DataValidationError* statesExample:
BindingValue<string> typed = BindingValue<string>.BindingError(
new InvalidOperationException("Missing source"),
fallbackValue: "(fallback)");
object? untyped = typed.ToUntyped();
BindingValue<string> roundTrip = BindingValue<string>.FromUntyped(untyped);
BindingChainException)BindingChainException is the dedicated exception type for binding chain parse/evaluation failures.
Constructor forms:
BindingChainException()BindingChainException(string message)BindingChainException(string message, string expression, string errorPoint)Diagnostic members:
ExpressionErrorPointMessageUse:
ExpressionErrorPoint in diagnostics UIs to show where the chain failed.Example:
catch (BindingChainException ex)
{
logger.LogWarning("Binding chain failed: {Message} @ {ErrorPoint}", ex.Message, ex.ExpressionErrorPoint);
}
BindingOperations.DoNothingType and No-Update SemanticsBindingOperations.DoNothing is a singleton marker whose runtime type is BindingOperations.DoNothingType.
Meaning:
Boundaries:
BindingOperations.DoNothingType in model state,AvaloniaProperty.UnsetValue (which means no value supplied by current source).InstancedBinding for Dynamic PipelinesInstancedBinding represents a binding already initiated for a concrete target context.
Factory helpers:
InstancedBinding.OneTime(...)InstancedBinding.OneWay(...)InstancedBinding.OneWayToSource(...)InstancedBinding.TwoWay(...)WithPriority(...)Key fields:
ModePrioritySourcePractical guidance:
InstancedBinding usage for dynamic composition/infrastructure,IBinding.Initiate(...) / BindingOperations.Apply(...) flows.For a bound property, BindingOperations.GetBindingExpressionBase(...) gives access to active expression control.
Useful controls:
UpdateSource() for explicit-update scenarios,UpdateTarget() for source-to-target refresh.Example:
var expr = BindingOperations.GetBindingExpressionBase(textBox, TextBox.TextProperty);
expr?.UpdateSource();
If you use UpdateSourceTrigger=Explicit, this call is required to push value back.
IndexerDescriptor and Property Indexer BindingAdvanced property-indexer binding path uses:
AvaloniaProperty operators ! and ~ to create IndexerDescriptor,IndexerDescriptor.WithMode(...) / WithPriority(...).IndexerDescriptor.SourceObservable for direct observable source pipelines.IndexerDescriptor.Description for diagnostics-friendly binding summaries.Example:
var descriptor = !TextBox.TextProperty;
textBox[descriptor.WithMode(BindingMode.TwoWay)] = new ReflectionBinding(nameof(ViewModel.Query));
Use this only when dynamic property selection is required. For normal authoring, regular Bind(...) or XAML bindings are clearer.
using Avalonia;
using Avalonia.Data;
IDisposable sub = textBox
.GetBindingObservable(TextBox.TextProperty)
.Subscribe(v =>
{
if (v.HasError)
{
viewModel.ValidationMessage = v.Error?.Message;
return;
}
if (v.Type == BindingValueType.Value)
viewModel.LastText = v.GetValueOrDefault() ?? string.Empty;
});
When a custom converter/adapter returns BindingOperations.DoNothing, target value is retained.
Use this for partial-update workflows where “no change” is a valid output state.
UpdateSource() on commit action.This gives deterministic source updates and avoids per-keystroke writes.
Advanced conversion paths can use runtime conversion logic (for example BindingValue<T>.FromUntyped(...)).
Guidance:
UnsetValue (fallback/default path) vs DoNothing (retain current target value).BindingError/DataValidationError with fallback values.UpdateSource() seems ineffective
TwoWay / OneWayToSource scenarios.InstancedBinding.Mode, Priority, and target property metadata default binding mode.Bind(...) or XAML binding unless dynamic property selection is a hard requirement.