FerroUI/ docs

Search guides, controls, Rust APIs, and XAML.

    GitHub ↗

    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:

    • initialize reads 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's Loading: 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.
    • update reads every binding again, OneTime bindings included.
    • stop_tracking releases what the OneWay and TwoWay bindings listen to and leaves the targets as they are; the bindings are uninitialized again, and the next attach (or initialize) 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.

    View source

    Members

    TYPE

    const TYPE: &'static $crate::TypeInfo
    

    The runtime type of this type.

    Source

    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.

    Source

    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, OneTime included.
    • The bindings of a root that is already attached to a visual tree, or of a Window that 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.

    Source

    is_initialized

    fn is_initialized(self: &Self) -> bool
    

    Whether the bindings were read and are tracking their sources.

    Source

    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.

    Source

    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.

    Source

    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.

    Source

    suspended_count

    fn suspended_count(self: &Self) -> usize
    

    The number of targets of bindings of a later phase that are hidden until their phase.

    Source

    binding_count

    fn binding_count(self: &Self) -> usize
    

    The number of live property bindings of the root.

    Source

    event_binding_count

    fn event_binding_count(self: &Self) -> usize
    

    The number of event bindings of the root.

    Source

    subscribed_event_count

    fn subscribed_event_count(self: &Self) -> usize
    

    The number of event bindings whose handler is subscribed to its event.

    Source

    initialize

    fn initialize(self: &Self) -> Result<(), XBindErrors>
    

    Initialize: reads the bindings if they are not initialized.

    Source

    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.

    Source

    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.

    Source

    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.

    Source

    Trait implementations

    Availability

    Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.