FerroUI/ docs

Search guides, controls, Rust APIs, and XAML.

    GitHub ↗

    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.

    View source

    Members

    new

    fn new() -> Rc<Self>
    

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

    Source

    with_path

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

    {x:Bind Path}.

    Source

    path

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

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

    Source

    set_path

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

    Source

    mode

    fn mode(self: &Self) -> BindingMode
    

    OneTime (the default), OneWay or TwoWay.

    Source

    set_mode

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

    Source

    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.

    Source

    set_update_source_trigger

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

    Source

    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.

    Source

    set_data_type

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

    Source

    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.

    Source

    set_target_type

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

    Source

    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.

    Source

    set_phase

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

    Source

    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.

    Source

    set_bind_back

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

    Source

    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}.

    Source

    set_converter

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

    Source

    converter_parameter

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

    ConverterParameter: the parameter the converter is called with.

    Source

    set_converter_parameter

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

    Source

    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.

    Source

    set_converter_language

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

    Source

    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.

    Source

    set_fallback_value

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

    Source

    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.

    Source

    set_target_null_value

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

    Source

    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.

    Source

    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).

    Source

    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).

    Source

    Trait implementations

    • Send
    • Sync
    • Freeze
    • UnsafeUnpin
    • Unpin
    • UnwindSafe
    • RefUnwindSafe
    • Borrow<T>
    • BorrowMut<T>
    • Into<U>
    • From<T>
    • TryInto<U>
    • TryFrom<U>
    • Any
    • AnyValue
    • ClassDefaults
    • ErasedDestructor
    • IntoEither
    • PartialEq
    • MarkupTyped

    Availability

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