Class BindingExtension
- Namespace
- Icy.Markup.Extensions
- Assembly
- IcyUI.dll
{Binding ...}: binds a property to a path evaluated against an explicit source, a named element, or
- the common case - the target's DataContext.
[MarkupExtensionDefaultProperty("Path")]
public sealed class BindingExtension : IMarkupExtension
- Inheritance
-
BindingExtension
- Implements
- Inherited Members
- Extension Methods
Remarks
{Binding Path=Name} can be shortened to {Binding Name} - Path is this extension's
default property. {Binding} with no path at
all binds the whole source object.
Binding to a property the property-registry marks non-bindable (AsTarget, or IsBindable) is an error, not a silent no-op - raised by TargetProperty itself, which this extension assigns through unchanged.
Always resolves to Unset: the binding is applied to the target directly (and, for the implicit-DataContext case, re-applied whenever DataContextChanged fires), so there is never a single value for the loader to assign afterward.
A path is static (resolved once on a known type), compiled (see Compiled), or dynamic (resolved on each read) when the source type is unknown; see the Data binding concept page.
Properties
Compiled
Gets or sets a value indicating whether the path is compiled into delegates (CompiledPropertyPath) instead of read through reflection.
public bool Compiled { get; set; }
Property Value
Remarks
Needs a known source type: an x:DataType on this element or an ancestor for a data-context binding, or
ElementName or Source. Without one, the markup fails to load.
A compiled data-context binding throws BindingException when the data context isn't the
x:DataType; a static one warns and falls back to a dynamic path. Under NativeAOT, compiled paths are
interpreted, at about the speed of static ones.
A path that reads a member of a property typed object (such as
SelectedItem.Name) can't be compiled: the member is
only known at run time. Such a path is read dynamically even with Compiled set, without an
error.
ElementName
Gets or sets the x:Name of the element to bind to, instead of the target's
DataContext.
public string? ElementName { get; set; }
Property Value
Mode
Gets or sets the binding's direction. Unset keeps the target property's own default (see DefaultTwoWayBinding).
public BindingMode? Mode { get; set; }
Property Value
Path
Gets or sets the path, relative to the source, to bind to. Unset (or empty) binds the source itself.
public string? Path { get; set; }
Property Value
Source
Gets or sets the object to bind to directly, instead of the target's DataContext.
public object? Source { get; set; }
Property Value
UpdateTargetTrigger
Gets or sets when the binding refreshes the target from the source. See UpdateTargetTrigger.
public UpdateTargetTrigger UpdateTargetTrigger { get; set; }
Property Value
Methods
ProvideValue(MarkupExtensionContext)
Computes the value the loader should use.
public object? ProvideValue(MarkupExtensionContext context)
Parameters
contextMarkupExtensionContextThe property being resolved, and what the loader knows about the document.
Returns
- object
The value to assign, converted the same way an ordinary attribute value would be; or Unset when the extension already applied its own effect (typically by binding the property itself) and nothing further should be assigned.
Exceptions
- MarkupException
One of the following:
- the target doesn't support bindings;
- the property isn't a registered one;
- ElementName names nothing in scope;
- the property is marked non-bindable;
-
the source type is known (an
x:DataType, ElementName or Source) and Path doesn't resolve on it; - Compiled is set without a known source type.