XBindExtension
struct · ferroui-markup-xaml · v0.5.0
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 for the target and registers it with the XBindings of its root, which reads
it when it is initialized (on Loading, see XBindings) and on every Update.
Members
newwith_pathpathset_pathmodeset_modeupdate_source_triggerset_update_source_triggerdata_typeset_data_typetarget_typeset_target_typephaseset_phasebind_backset_bind_backconverterset_converterconverter_parameterset_converter_parameterconverter_languageset_converter_languagefallback_valueset_fallback_valuetarget_null_valueset_target_null_valuevalidatecreate_bindingprovide_value
new
fn new() -> Rc<Self>
{x:Bind}: a binding to the root source itself.
with_path
fn with_path(path: CompiledBindingPath) -> Rc<Self>
{x:Bind Path}.
path
fn path(self: &Self) -> Option<CompiledBindingPath>
The compiled path, read from the root source; None reads the root source itself.
set_path
fn set_path(self: &Self, path: Option<CompiledBindingPath>)
mode
fn mode(self: &Self) -> BindingMode
OneTime (the default), OneWay or TwoWay.
set_mode
fn set_mode(self: &Self, mode: BindingMode)
update_source_trigger
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.
set_update_source_trigger
fn set_update_source_trigger(self: &Self, trigger: UpdateSourceTrigger)
data_type
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.
set_data_type
fn set_data_type(self: &Self, data_type: Option<ValueType>)
target_type
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.
set_target_type
fn set_target_type(self: &Self, target_type: Option<ValueType>)
phase
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.
set_phase
fn set_phase(self: &Self, phase: i32)
bind_back
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.
set_bind_back
fn set_bind_back(self: &Self, bind_back: Option<String>)
converter
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}.
set_converter
fn set_converter(self: &Self, converter: Option<Rc<dyn IValueConverter>>)
converter_parameter
fn converter_parameter(self: &Self) -> Option<BoxedValue>
ConverterParameter: the parameter the converter is called with.
set_converter_parameter
fn set_converter_parameter(self: &Self, parameter: Option<BoxedValue>)
converter_language
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.
set_converter_language
fn set_converter_language(self: &Self, language: Option<CultureInfo>)
fallback_value
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.
set_fallback_value
fn set_fallback_value(self: &Self, value: Option<BoxedValue>)
target_null_value
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.
set_target_null_value
fn set_target_null_value(self: &Self, value: Option<BoxedValue>)
validate
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.
create_binding
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).
provide_value
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).
Trait implementations
SendSyncFreezeUnsafeUnpinUnpinUnwindSafeRefUnwindSafeBorrow<T>BorrowMut<T>Into<U>From<T>TryInto<U>TryFrom<U>AnyAnyValueClassDefaultsErasedDestructorIntoEitherPartialEqMarkupTyped
Availability
Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.