FerroUI/ docs

Search guides, controls, Rust APIs, and XAML.

    GitHub ↗

    template

    function · ferroui-view · v0.5.0

    fn template<T, E>(view: impl Fn(T) -> E + 'static) -> std::rc::Rc<dyn IDataTemplate>
    where T: Clone + 'static,
          E: IntoElement
    

    A data template whose item is a component: for the ItemTemplate of an items control or the ContentTemplate of a content control.

    list_box()
        .items_source(people)
        .item_template(template(|person: Person| rsx! { TextBlock { text: person.name } }))
    

    Each item container gets a ComponentHost whose component runs view with the item (the DataContext of the container). The template matches data of type T. What view makes sees the contexts of the owner that was current when the template was made.

    The template recycles. A host that leaves the visual tree (a virtualizing panel took its container away, a list removed its item) keeps its component mounted, with its last item, and waits in a pool of the template. The next item that needs a host takes one from the pool: its component runs again with the new item and the reconciler patches its controls, so scrolling a long list makes no new controls once the pool has the hosts of a screen. The pool ends its hosts when the template is dropped.

    View source

    Availability

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