# XBindExtension

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

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

```rust
struct XBindExtension
```

`{x:Bind Path, Mode=..., UpdateSourceTrigger=..., BindBack=...}`: a binding whose path the
compiler resolved against the root of its document, or against the `x:DataType` of the
`DataTemplate` it is in.

Markup writes it as `x:Bind` (the XAML language namespace, as WinUI) or as `XBind` (the
framework namespace); the compiler maps the first onto the second. The compiler sets
`data_type` for a binding inside a typed `DataTemplate`: the binding then
reads the data context of the template's root, which must be of that type; without it the
binding reads the root object of its document itself.

The path has the grammar of WinUI's compiled bindings: properties, attached properties
(`path.(Owner.Property)`), static members (`ns:Type.Member`), indexers (`Items[0]`,
`Map['key']`), casts (`(ns:Type)path`, `((ns:Type)path).Member`) and a function at its end
(`Format(Name, 'text', 3)`, `Model.Format(Name)`, `ns:Type.Format(Name)`), compiled into the
elements of a `CompiledBindingPath`. A `TwoWay` binding through a function writes back
through the method `bind_back` names, which the compiler resolves into
the function element of the path.

The value of the path goes through a `converter` (an `IValueConverter`,
with its `converter_parameter` and the culture
`converter_language` names; `ConvertBack` on the way back of a
`TwoWay` binding), and `fallback_value` and
`target_null_value` stand for a path that cannot be read (a null
in the middle of it, a failure) and for a null value (step X3).

On an event (`Click="{x:Bind OnClick}"`, `Click="{x:Bind Model.OnClick}"`,
`Click="{x:Bind local:Handlers.OnClick}"`) the path ends with the method the event calls,
which the compiler resolves into the event handler element of the path; the binding the
extension provides subscribes the handler while the bindings of the root are initialized
(step X4, `XBinding::bind_routed_event`).

Inside a `ControlTemplate` the compiler sets `target_type`, the
`TargetType` of the template: the binding reads the templated parent of the root of the
template instance, which must be of that type (step X5). Inside a typed `DataTemplate` the
compiler sets `phase` from the `x:Phase` of the element the binding is on: a
container reads the binding in that phase of the instance (`IDataTemplateComponent`).

The default mode is `OneTime`, as WinUI's; the compiler gives the binding the mode of the
nearest `x:DefaultBindMode` around it when the markup names none. Providing the value creates
an [`XBinding`](/docs/0.5.0/api/ferroui-markup-xaml/markup_extensions/struct-xbinding/) for the target and registers it with the [`XBindings`](/docs/0.5.0/api/ferroui-markup-xaml/markup_extensions/struct-xbindings/) of its root, which reads
it when it is initialized (on `Loading`, see [`XBindings`](/docs/0.5.0/api/ferroui-markup-xaml/markup_extensions/struct-xbindings/)) and on every `Update`.

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Markup/FerroUI.Markup.Xaml/markup_extensions/x_bind/extension.rs#L58)

## Members

- [`new`](#function-new)
- [`with_path`](#function-with_path)
- [`path`](#function-path)
- [`set_path`](#function-set_path)
- [`mode`](#function-mode)
- [`set_mode`](#function-set_mode)
- [`update_source_trigger`](#function-update_source_trigger)
- [`set_update_source_trigger`](#function-set_update_source_trigger)
- [`data_type`](#function-data_type)
- [`set_data_type`](#function-set_data_type)
- [`target_type`](#function-target_type)
- [`set_target_type`](#function-set_target_type)
- [`phase`](#function-phase)
- [`set_phase`](#function-set_phase)
- [`bind_back`](#function-bind_back)
- [`set_bind_back`](#function-set_bind_back)
- [`converter`](#function-converter)
- [`set_converter`](#function-set_converter)
- [`converter_parameter`](#function-converter_parameter)
- [`set_converter_parameter`](#function-set_converter_parameter)
- [`converter_language`](#function-converter_language)
- [`set_converter_language`](#function-set_converter_language)
- [`fallback_value`](#function-fallback_value)
- [`set_fallback_value`](#function-set_fallback_value)
- [`target_null_value`](#function-target_null_value)
- [`set_target_null_value`](#function-set_target_null_value)
- [`validate`](#function-validate)
- [`create_binding`](#function-create_binding)
- [`provide_value`](#function-provide_value)

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

### new

```rust
fn new() -> Rc<Self>
```

`{x:Bind}`: a binding to the root source itself.

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

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

### with_path

```rust
fn with_path(path: CompiledBindingPath) -> Rc<Self>
```

`{x:Bind Path}`.

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

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

### path

```rust
fn path(self: &Self) -> Option<CompiledBindingPath>
```

The compiled path, read from the root source; `None` reads the root source itself.

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

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

### set_path

```rust
fn set_path(self: &Self, path: Option<CompiledBindingPath>)
```



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

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

### mode

```rust
fn mode(self: &Self) -> BindingMode
```

`OneTime` (the default), `OneWay` or `TwoWay`.

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

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

### set_mode

```rust
fn set_mode(self: &Self, mode: BindingMode)
```



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

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

### update_source_trigger

```rust
fn update_source_trigger(self: &Self) -> UpdateSourceTrigger
```

When a `TwoWay` binding writes the target value back: `Default` (on `LostFocus` for
`TextBox.Text`, else on every change), `PropertyChanged` or `LostFocus`.

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

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

### set_update_source_trigger

```rust
fn set_update_source_trigger(self: &Self, trigger: UpdateSourceTrigger)
```



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

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

### data_type

```rust
fn data_type(self: &Self) -> Option<ValueType>
```

The `x:DataType` of the `DataTemplate` the binding is in, which the compiler sets; `None`
outside a template.

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

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

### set_data_type

```rust
fn set_data_type(self: &Self, data_type: Option<ValueType>)
```



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

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

### target_type

```rust
fn target_type(self: &Self) -> Option<ValueType>
```

The `TargetType` of the `ControlTemplate` the binding is in, which the compiler sets: the
binding then reads the templated parent of the root of the template instance. `None`
outside a control template.

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

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

### set_target_type

```rust
fn set_target_type(self: &Self, target_type: Option<ValueType>)
```



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

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

### phase

```rust
fn phase(self: &Self) -> i32
```

The `x:Phase` of the element the binding is on, which the compiler sets: `0` (the
default) is read when a container prepares the template instance, a later phase when
the container processes that phase.

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

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

### set_phase

```rust
fn set_phase(self: &Self, phase: i32)
```



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

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

### bind_back

```rust
fn bind_back(self: &Self) -> Option<String>
```

`BindBack`: the method a `TwoWay` binding through a function writes the value of its
target with, as markup names it (`ParseName`, `Model.SetName`, `local:Helpers.Parse`).
The compiler resolves it into the function element of the path; the extension keeps
the text.

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

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

### set_bind_back

```rust
fn set_bind_back(self: &Self, bind_back: Option<String>)
```



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

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

### converter

```rust
fn converter(self: &Self) -> Option<Rc<dyn IValueConverter>>
```

`Converter`: the `IValueConverter` the value of the path goes through (`Convert` to the
target, `ConvertBack` to the source of a `TwoWay` binding). Markup gives it as a
`{StaticResource}`.

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

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

### set_converter

```rust
fn set_converter(self: &Self, converter: Option<Rc<dyn IValueConverter>>)
```



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

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

### converter_parameter

```rust
fn converter_parameter(self: &Self) -> Option<BoxedValue>
```

`ConverterParameter`: the parameter the converter is called with.

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

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

### set_converter_parameter

```rust
fn set_converter_parameter(self: &Self, parameter: Option<BoxedValue>)
```



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

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

### converter_language

```rust
fn converter_language(self: &Self) -> Option<CultureInfo>
```

`ConverterLanguage`: the culture the converter is called with, which markup names by its
language tag (`fr-FR`); `None` is the current culture.

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

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

### set_converter_language

```rust
fn set_converter_language(self: &Self, language: Option<CultureInfo>)
```



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

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

### fallback_value

```rust
fn fallback_value(self: &Self) -> Option<BoxedValue>
```

`FallbackValue`: the value of the target when the path cannot be read (a null in the
middle of it, a failure); the unset marker (the default) for none, `None` for `x:Null`.

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

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

### set_fallback_value

```rust
fn set_fallback_value(self: &Self, value: Option<BoxedValue>)
```



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

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

### target_null_value

```rust
fn target_null_value(self: &Self) -> Option<BoxedValue>
```

`TargetNullValue`: the value of the target when the value of the path is null; the
unset marker (the default) for none.

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

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

### set_target_null_value

```rust
fn set_target_null_value(self: &Self, value: Option<BoxedValue>)
```



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

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

### validate

```rust
fn validate(self: &Self) -> Result<(), XamlLoadError>
```

Checks the mode, the update trigger and the converter as WinUI's compiler does
(`BindAssignment.ValidateUpdateSourceTrigger`, `ValidateConverter`). The compiler reports
the same errors with the position of the binding; this covers an extension made in code.

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

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

### create_binding

```rust
fn create_binding(self: &Self, root: &BoxedValue, name_scope: Option<&NameScopeRef>) -> Result<Rc<XBinding>, XamlLoadError>
```

The binding of one target, registered with the `XBindings` of `root`: the root object
of the document, or the root of the template instance for a binding with a data type or
a target type. `name_scope` is the name scope of the place the binding is declared in; a
template instance keeps it (see `XBindings`).

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

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

### provide_value

```rust
fn provide_value(self: &Self, provider: &Rc<dyn IServiceProvider>) -> Result<Rc<XBinding>, XamlLoadError>
```

`ProvideValue`: the binding of the target the extension is provided for. Its root is the
root object of the document (`IRootObjectProvider.RootObject`), or, inside a typed data
template or a control template, the root of the template instance
(`IntermediateRootObject`).

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

## 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`
- `PartialEq`
- [`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/).
