stride3d/stride · error · InvalidOperationException

Unable to reach the ItemsPresenter of the associated…

Error message

Unable to reach the ItemsPresenter of the associated ItemsControl.

What it means

TilePanelThumbnailPrioritizationBehavior.GetItemsPanel searches the visual tree of the associated ItemsControl for an ItemsPresenter. If none is found (visual tree not built yet or template replaced), it throws InvalidOperationException because it cannot locate the items panel to prioritize thumbnail loading.

Solutions

  1. Ensure the behavior's loaded handler runs after the template is applied and the panel is realized (hook to ItemsControl.Loaded / ItemContainerGenerator.StatusChanged)
  2. Verify the ItemsControl's ControlTemplate contains an ItemsPresenter
  3. Ensure the ItemsSource has items so the presenter and panel are materialized

Example fix

// before
private void OnAttachedAndLoaded(object s, RoutedEventArgs e) => GetItemsPanel(AssociatedObject);
// after
private void OnAttachedAndLoaded(object s, RoutedEventArgs e)
{
    if (AssociatedObject.FindVisualChildOfType<ItemsPresenter>() == null)
        return; // retry on next Loaded / generator status change
    GetItemsPanel(AssociatedObject);
}
Defensive patterns

Strategy: validation

Validate before calling

if (itemsControl.FindVisualChildOfType<ItemsPresenter>() == null)
    return; // not realized yet; retry on Loaded / ItemContainerGenerator.StatusChanged

Type guard

static bool HasItemsPresenter(Visual root) => root.FindVisualChildOfType<ItemsPresenter>() != null;

Try / catch

try { var panel = GetItemsPanel(itemsControl); }
catch (InvalidOperationException) { itemsControl.ItemContainerGenerator.StatusChanged += RetryWhenRealized; }

Prevention

When it happens

Trigger: OnAttachedAndLoaded runs while the ItemsControl has not yet generated its visual children (no items, virtualization not realized, control not in the visual tree) or its ControlTemplate lacks an ItemsPresenter.

Common situations: Attaching the behavior to a collapsed/never-realized ItemsControl; empty items source so the presenter is not instantiated; custom template missing the ItemsPresenter part.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/db6ff12ba5164415. Report an issue: GitHub.

Appendix: source

Thrown at sources/editor/Stride.Core.Assets.Editor/View/Behaviors/TilePanelThumbnailPrioritizationBehavior.cs:55

            previousFirstVisibleItemIndex = firstVisibleItemIndex;
            previousLastVisibleItemIndex = lastVisibleItemIndex;

            var items = AssociatedObject.ItemsSource?.Cast<ISessionObjectViewModel>().ToList();
            if (items == null || firstVisibleItemIndex > lastVisibleItemIndex)
                return;

            var session = items[0].Session;
            var visibleAssets = items.Subset(firstVisibleItemIndex, lastVisibleItemIndex - firstVisibleItemIndex + 1).OfType<AssetViewModel>();
            session.Thumbnails.IncreaseThumbnailPriority(visibleAssets);
        }

        private static VirtualizingTilePanel GetItemsPanel(DependencyObject itemsControl)
        {
            var itemsPresenter = itemsControl.FindVisualChildOfType<ItemsPresenter>();

            if (itemsPresenter == null)
                throw new InvalidOperationException("Unable to reach the ItemsPresenter of the associated ItemsControl.");

            var itemsPanel = (VirtualizingTilePanel)VisualTreeHelper.GetChild(itemsPresenter, 0);

            if (itemsPanel == null)
                throw new InvalidOperationException("Unable to reach the VirtualizingTilePanel of the associated ItemsControl.");
            return itemsPanel;
        }
    }
}

View on GitHub (pinned to 96fad776d2)