Skip to content
FerroUI/ docs

Search guides, controls, Rust APIs, and XAML.

    Share resources

    Resources give reusable values a key: brushes, styles, templates, dimensions, and other objects can be declared once and referenced from several controls.

    <StackPanel xmlns="https://github.com/ferroui" Spacing="12">
    <StackPanel.Resources>
    <SolidColorBrush xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Key="AccentBrush" Color="#2459E0" />
    </StackPanel.Resources>
    <TextBlock Foreground="{StaticResource AccentBrush}" Text="Shared color" />
    </StackPanel>

    Use static lookup when the resource is stable. Use dynamic lookup when the value is expected to change through theme or resource updates. Keep an application’s theme resources at a scope shared by the controls that consume them.

    Resources are part of the property system, not of XAML alone. A declarative component reads a resource as the control it is mounted in finds it, and follows changes, with use_resource(key) or use_resource_as::<T>(key); see styles, themes & motion.

    Resource lookup follows framework resource-provider relationships, not arbitrary Rust module relationships. A resource declared inside one view is not automatically visible to an unrelated window. Check the logical ancestry and application resources when a key resolves in one location but not another.

    A local property value can override a style that uses a resource. If a resource change appears to have no effect, inspect the property’s effective value source before changing the resource dictionary.

    Control templates introduce their own visual structure. Use the appropriate template binding to forward an owning control’s property instead of hard-coding a value inside its template. Keep resource keys stable when an application is intended to let consumers replace them.

    Test resource lookup in both light and dark variants, and after changing the active theme while the application is running.

    Change the example label to Foreground="{DynamicResource AccentBrush}" when the brush may be replaced while the view is open. Replace the resource at the scope that owns AccentBrush; the dynamic consumer should update. A static lookup is appropriate when that value will remain fixed for the view’s lifetime.

    For an application with two windows, place a shared accent at application scope, and put a view-specific spacing value in that view’s resources. Do not copy the accent dictionary into each window unless independent values are intentional.

    If a key is missing, first inspect the consumer’s resource scope. If the key resolves but the color is wrong, inspect the effective property value and competing assignments. These are different failures.

    Use a merge include for shared resource units. For example, a dictionary can load a palette file relative to its own document:

    <ResourceDictionary xmlns="https://github.com/ferroui">
    <ResourceDictionary.MergedDictionaries>
    <MergeResourceInclude Source="Palette.xaml" />
    </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>

    Put Palette.xaml alongside the including file and register both as application XAML assets. For a runtime document group, supply an absolute document URL and ensure the asset loader can resolve the nested includes. This also applies to dictionaries declared inline. An isolated string loaded without a base URL cannot resolve a relative file merely because it exists next to your Rust source.

    See runtime loading and themes.

    Use an absolute url::Url for a document’s loading context. Use UriRef for a value that may be relative, such as a hyperlink target. For example, in an initialized view:

    use ferroui_base::utilities::UriRef;
    use ferroui_controls::HyperlinkButton;
    let link = HyperlinkButton::new();
    link.set_navigate_uri(Some(UriRef::parse("https://example.com/help")?));

    The fragment belongs in a function that handles URL parse errors. A relative value needs a base before a platform service can open it. For storage, a provider may expose a virtual item without a local filesystem path; use the provider’s stream API when a path is unavailable.