Skip to content
FerroUI/ docs

Search guides, controls, Rust APIs, and XAML.

    Display and update collections

    Display a sequence of data either as children that follow a list in your state, or with an items control and a data template that describes one item. Avoid manually creating controls for every data object when the collection needs selection, sorting, or virtualization.

    In a component that runs again, repeat children with for and give each a stable key:

    use ferroui_view::prelude::*;
    #[derive(Clone, PartialEq)]
    pub struct SearchResult {
    pub id: u32,
    pub name: String,
    }
    #[component(rerender)]
    fn Results(results: Vec<SearchResult>) -> Element {
    rsx! {
    ListBox {
    for result in &results {
    ListBoxItem { key: result.id, content: result.name.clone() }
    }
    }
    }
    }

    The items of results that stay keep their controls when the list is filtered or reordered. In a view that runs once, for_each(move || results.get(), |r: &SearchResult| r.id, |r: SearchResult| ..) follows a signal of the list instead. For thousands of records, give a virtualizing ListBox an items_source and item_template: template(|item: T| ..), whose items are components recycled as the list scrolls (lists, async data & routing).

    This fragment uses explicit reflection bindings because it omits your application’s registered source types. See compiled binding setup for typed XAML.

    <ListBox xmlns="https://github.com/ferroui"
    ItemsSource="{ReflectionBinding Results}"
    SelectedItem="{ReflectionBinding SelectedResult, Mode=TwoWay}">
    <ListBox.ItemTemplate>
    <DataTemplate>
    <TextBlock Text="{ReflectionBinding Name}" />
    </DataTemplate>
    </ListBox.ItemTemplate>
    </ListBox>

    Inside an initialized application’s view setup, a notifying collection can be connected directly to a list:

    use std::rc::Rc;
    use ferroui_controls::{ItemsSource, ListBox};
    use ferroui_system::collections::object_model::ObservableCollection;
    let names = ObservableCollection::<String>::new();
    names.add("Ada".to_owned());
    let list = ListBox::new();
    list.set_items_source(Some(ItemsSource::new(Rc::new(names.clone()))));
    names.add("Grace".to_owned());

    Add list to the view. Both names should appear, including the item added after assigning the source. Cloning this collection shares its state; keep a handle in the model when later commands need to edit it.

    For the templated XAML above, expose Results as an items source, SelectedResult as a writable notifying property, and Name on each item. The binding inside a data template sees the row’s data context, so it reads the row’s Name rather than a property on the whole screen.

    Adding or removing a row requires a collection-change notification. Editing a property on an existing row requires that item’s property-change notification. Replacing a plain Rust vector without notifying the bound property does neither automatically.

    FerroUI’s observable collections serve straightforward UI lists. DynamicData offers change sets and transformations for applications that filter, sort, and combine changing collections. Prefer a view-model projection over rebuilding the control tree from an unrelated event handler.

    Keep stable item identities while updating data. Replacing every item object can reset selection or expanded state even when the displayed text is unchanged. Explicitly define what selection means when filtering removes the selected item.

    Give a virtualized items control a bounded viewport. Wrapping it in an unconstrained outer scrolling container may defeat virtualization. Keep templates small, avoid synchronous I/O in getters, and measure scrolling with realistic data.

    For hierarchical rows and columns, use the TreeDataGrid ecosystem guide; for a simple single selection, start with ListBox. Choose a control.

    This preview demonstrates selection with static items. The Rust collection example above adds model-driven updates in an application.

    Select an itemFerroUI · 0.5.0
    Try it for yourself

    Real controls, running in WebAssembly.
    The runtime downloads when you press Run.

    Shared runtime · 9.8 MB compressed · cached across examples
    Download project
    <ListBox xmlns="https://github.com/ferroui" SelectedIndex="1" Height="180">
    <ListBoxItem>Design</ListBoxItem>
    <ListBoxItem>Build</ListBoxItem>
    <ListBoxItem>Ship</ListBoxItem>
    </ListBox>
    Ready to explore