lepoco/wpfui · error · ArgumentNullException

Item content is null

Error message

Item content is null

What it means

Thrown by BreadcrumbBar.OnTemplateButtonClick when the clicked item (obj) is null. The click handler resolves the container and index from the item, so a null item is treated as an invalid argument (ArgumentNullException) rather than silently ignored.

Source

Thrown at src/Wpf.Ui/Controls/BreadcrumbBar/BreadcrumbBar.cs:167

        );
        UpdateLastContainer();
    }

    private void ItemContainerGeneratorOnItemsChanged(object sender, ItemsChangedEventArgs e)
    {
        if (e.Action != NotifyCollectionChangedAction.Remove)
        {
            return;
        }

        UpdateLastContainer();
    }

    private void OnTemplateButtonClick(object? obj)
    {
        if (obj is null)
        {
            throw new ArgumentNullException("Item content is null");
        }

        DependencyObject container = ItemContainerGenerator.ContainerFromItem(obj);
        int index = ItemContainerGenerator.IndexFromContainer(container);

        OnItemClicked(obj, index);
    }

    private void InteractWithItemContainer(int offsetFromEnd, Action<BreadcrumbBarItem> action)
    {
        if (ItemContainerGenerator.Items.Count <= 0)
        {
            return;
        }

        var item = ItemContainerGenerator.Items[^offsetFromEnd];
        var container = (BreadcrumbBarItem)ItemContainerGenerator.ContainerFromItem(item);

View on GitHub (pinned to ffebacd610)

Solutions

  1. Ensure each BreadcrumbBar item template's clickable element passes the non-null item as its command parameter (CommandParameter="{Binding}" or DataContext-based).
  2. Filter null entries out of the ItemsSource before binding.
  3. Avoid null items in the underlying collection; initialize items to non-null placeholders.

Example fix

// before
<Button Command="{Binding RelativeSource={RelativeSource AncestorType=ui:BreadcrumbBar}, Path=TemplateClickCommand}" />

// after
<Button Command="{Binding RelativeSource={RelativeSource AncestorType=ui:BreadcrumbBar}, Path=TemplateClickCommand}"
        CommandParameter="{Binding}" />
Defensive patterns

Strategy: validation

Validate before calling

if (obj is null) { return; } // guard before OnTemplateButtonClick logic

Type guard

static bool IsValidBreadcrumbItem(object? o) => o is not null;

Prevention

When it happens

Trigger: A template button in the BreadcrumbBar fires its click command with a null payload, e.g. a Button whose CommandParameter is unset or bound to a null collection element. OnTemplateButtonClick receives null and throws.

Common situations: Custom BreadcrumbBar item templates where the button's CommandParameter is not wired to {Binding} of the item, a data source containing null entries, or an items-source reset that leaves a stale button bound to null.

Related errors


AI-assisted analysis of lepoco/wpfui@ffebacd610 (2026-08-13). Data as JSON: /api/errors/5a1909d44b15a85c. Report an issue: GitHub.