XBindings
struct · ferroui-markup-xaml · v0.5.0
struct XBindings
The {x:Bind} bindings of one root: a document root or the root of one template instance.
It is the object WinUI's compiler generates as the Bindings of a page, with the same
lifecycle:
initializereads every binding once, unless the bindings are already initialized. The root of a document calls it when it is attached to a visual tree, the counterpart of WinUI'sLoading: after construction and after code-behind has set what the bindings read. A root that is not a visual, or that is already in a tree when its document is built, is initialized by calling it.updatereads every binding again,OneTimebindings included.stop_trackingreleases what theOneWayandTwoWaybindings listen to and leaves the targets as they are; the bindings are uninitialized again, and the next attach (orinitialize) reads them.
The event bindings of the root (Click="{x:Bind OnClick}") subscribe their handlers when the
bindings are initialized or updated and release them when the bindings stop tracking; a
handler reads the path of its method when the event is raised.
The root of a template instance (a DataTemplate with x:DataType) is updated whenever its
data context changes to an item, as the generated DataContextChangedHandler: a recycled
container reads its new item, OneTime bindings included. A null data context reads nothing.
The bindings of a template instance are also its IDataTemplateComponent, which the root
carries (XamlBindingHelper.DataTemplateComponent): a container that drives the instance
through it (ProcessBindings with phase 0 when it prepares the element, then each phase
the previous call returned, Recycle before reusing it) reads its bindings phase by phase
(x:Phase) from the item it gives, and the data context no longer drives the instance. The
targets of a later phase are hidden until their phase, and again when the element is recycled
(WinUI's SuspendRendering and ResumeRendering).
The root of a control template instance (a ControlTemplate with TargetType) reads its
templated parent, and is updated whenever its templated parent changes to a control; it stops
tracking when the template is removed. The root of a Window document is initialized when
the window is activated (WinUI's Activated), every other document root when it is attached
to a visual tree.
XBindings::get_for_root finds the object of a root; the first x:Bind of a root creates
it. The root owns it; it holds the root and its bindings weakly.
Members
TYPEget_for_rootupdate_populatedis_initializedis_templateis_control_templateis_container_drivensuspended_countbinding_countevent_binding_countsubscribed_event_countinitializeupdatestop_trackingdiagnostics
TYPE
const TYPE: &'static $crate::TypeInfo
The runtime type of this type.
get_for_root
fn get_for_root(root: &FerroObject) -> Option<Rc<Self>>
The bindings of root, if an x:Bind of its document (or template) created them.
update_populated
fn update_populated(root: &FerroObject) -> Result<(), XBindErrors>
After a document populated root again, or populated a root that is already live (step
X7: hot reload, a designer, a live root loaded into): what the bindings of the root need
so that they reflect the markup that was just populated.
- Initialized bindings are read again (
update): the bindings the new markup added are read, the others read their sources again,OneTimeincluded. - The bindings of a root that is already attached to a visual tree, or of a
Windowthat is already active, are initialized: no attach (or activation) is coming to do it. - Otherwise nothing: the attach to a visual tree (or the activation) initializes them, as for a document built before it is shown.
A root without x:Bind bindings, and the root of a template instance (its data context
or its container drives it), have nothing to do.
is_initialized
fn is_initialized(self: &Self) -> bool
Whether the bindings were read and are tracking their sources.
is_template
fn is_template(self: &Self) -> bool
Whether these are the bindings of a template instance: of a data template or of a control template.
is_control_template
fn is_control_template(self: &Self) -> bool
Whether these are the bindings of a control template instance, which read the templated parent of their root.
is_container_driven
fn is_container_driven(self: &Self) -> bool
Whether a container drives the template instance through its template component
(IDataTemplateComponent) instead of its data context.
suspended_count
fn suspended_count(self: &Self) -> usize
The number of targets of bindings of a later phase that are hidden until their phase.
binding_count
fn binding_count(self: &Self) -> usize
The number of live property bindings of the root.
event_binding_count
fn event_binding_count(self: &Self) -> usize
The number of event bindings of the root.
subscribed_event_count
fn subscribed_event_count(self: &Self) -> usize
The number of event bindings whose handler is subscribed to its event.
initialize
fn initialize(self: &Self) -> Result<(), XBindErrors>
Initialize: reads the bindings if they are not initialized.
update
fn update(self: &Self) -> Result<(), XBindErrors>
Update: reads every binding again, OneTime bindings included. The failures are
returned together and stay available through diagnostics.
stop_tracking
fn stop_tracking(self: &Self)
StopTracking: releases the sources the bindings listen to and keeps the values of the
targets. The bindings are uninitialized; the next Initialize (or attach) reads them.
diagnostics
fn diagnostics(self: &Self) -> Vec<XBindDiagnostic>
The current failures, including those of a source change of a OneWay or TwoWay
binding. Reading them evaluates nothing.
Trait implementations
SendSyncFreezeUnsafeUnpinUnpinUnwindSafeRefUnwindSafeBorrow<T>BorrowMut<T>Into<U>From<T>TryInto<U>TryFrom<U>AnyAnyValueClassDefaultsErasedDestructorIntoEitherStaticTypePartialEqIDataTemplateComponentMarkupTyped
Availability
Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.