# XBindings

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-markup-xaml/markup_extensions/struct-xbindings/

**struct** · [`ferroui-markup-xaml`](/docs/0.5.0/api/ferroui-markup-xaml/) · v0.5.0

```rust
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](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Markup/FerroUI.Markup.Xaml/markup_extensions/x_bind/bindings.rs#L104)

## Members

- [`TYPE`](#assoc_const-type)
- [`get_for_root`](#function-get_for_root)
- [`update_populated`](#function-update_populated)
- [`is_initialized`](#function-is_initialized)
- [`is_template`](#function-is_template)
- [`is_control_template`](#function-is_control_template)
- [`is_container_driven`](#function-is_container_driven)
- [`suspended_count`](#function-suspended_count)
- [`binding_count`](#function-binding_count)
- [`event_binding_count`](#function-event_binding_count)
- [`subscribed_event_count`](#function-subscribed_event_count)
- [`initialize`](#function-initialize)
- [`update`](#function-update)
- [`stop_tracking`](#function-stop_tracking)
- [`diagnostics`](#function-diagnostics)

<a id="assoc_const-type"></a>

### TYPE

```rust
const TYPE: &'static $crate::TypeInfo
```

The runtime type of this type.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Markup/FerroUI.Markup.Xaml/markup_extensions/x_bind/bindings.rs#L141)

<a id="function-get_for_root"></a>

### get_for_root

```rust
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](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Markup/FerroUI.Markup.Xaml/markup_extensions/x_bind/bindings.rs#L213)

<a id="function-update_populated"></a>

### update_populated

```rust
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](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Markup/FerroUI.Markup.Xaml/markup_extensions/x_bind/bindings.rs#L231)

<a id="function-is_initialized"></a>

### is_initialized

```rust
fn is_initialized(self: &Self) -> bool
```

Whether the bindings were read and are tracking their sources.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Markup/FerroUI.Markup.Xaml/markup_extensions/x_bind/bindings.rs#L253)

<a id="function-is_template"></a>

### is_template

```rust
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](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Markup/FerroUI.Markup.Xaml/markup_extensions/x_bind/bindings.rs#L259)

<a id="function-is_control_template"></a>

### is_control_template

```rust
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](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Markup/FerroUI.Markup.Xaml/markup_extensions/x_bind/bindings.rs#L265)

<a id="function-is_container_driven"></a>

### is_container_driven

```rust
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](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Markup/FerroUI.Markup.Xaml/markup_extensions/x_bind/bindings.rs#L271)

<a id="function-suspended_count"></a>

### suspended_count

```rust
fn suspended_count(self: &Self) -> usize
```

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Markup/FerroUI.Markup.Xaml/markup_extensions/x_bind/bindings.rs#L276)

<a id="function-binding_count"></a>

### binding_count

```rust
fn binding_count(self: &Self) -> usize
```

The number of live property bindings of the root.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Markup/FerroUI.Markup.Xaml/markup_extensions/x_bind/bindings.rs#L281)

<a id="function-event_binding_count"></a>

### event_binding_count

```rust
fn event_binding_count(self: &Self) -> usize
```

The number of event bindings of the root.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Markup/FerroUI.Markup.Xaml/markup_extensions/x_bind/bindings.rs#L286)

<a id="function-subscribed_event_count"></a>

### subscribed_event_count

```rust
fn subscribed_event_count(self: &Self) -> usize
```

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Markup/FerroUI.Markup.Xaml/markup_extensions/x_bind/bindings.rs#L291)

<a id="function-initialize"></a>

### initialize

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

`Initialize`: reads the bindings if they are not initialized.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Markup/FerroUI.Markup.Xaml/markup_extensions/x_bind/bindings.rs#L296)

<a id="function-update"></a>

### update

```rust
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](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Markup/FerroUI.Markup.Xaml/markup_extensions/x_bind/bindings.rs#L306)

<a id="function-stop_tracking"></a>

### stop_tracking

```rust
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](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Markup/FerroUI.Markup.Xaml/markup_extensions/x_bind/bindings.rs#L351)

<a id="function-diagnostics"></a>

### diagnostics

```rust
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](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Markup/FerroUI.Markup.Xaml/markup_extensions/x_bind/bindings.rs#L363)

## Trait implementations

- `Send`
- `Sync`
- `Freeze`
- `UnsafeUnpin`
- `Unpin`
- `UnwindSafe`
- `RefUnwindSafe`
- `Borrow<T>`
- `BorrowMut<T>`
- `Into<U>`
- `From<T>`
- `TryInto<U>`
- `TryFrom<U>`
- `Any`
- [`AnyValue`](/docs/0.5.0/api/ferroui-base/trait-anyvalue/)
- [`ClassDefaults`](/docs/0.5.0/api/ferroui-base/trait-classdefaults/)
- `ErasedDestructor`
- `IntoEither`
- [`StaticType`](/docs/0.5.0/api/ferroui-base/trait-statictype/)
- `PartialEq`
- [`IDataTemplateComponent`](/docs/0.5.0/api/ferroui-controls-repeater/use-idatatemplatecomponent/)
- [`MarkupTyped`](/docs/0.5.0/api/ferroui-base/metadata/trait-markuptyped/)

## Availability

Extracted for `aarch64-apple-darwin`. Cargo features are listed in the [crate index](/docs/0.5.0/api/).
