{"record":{"id":"db6ff12ba5164415","repo":"stride3d/stride","slug":"unable-to-reach-the-itemspresenter-of-the-associated","errorCode":null,"errorMessage":"Unable to reach the ItemsPresenter of the associated ItemsControl.","messagePattern":"Unable to reach the ItemsPresenter of the associated ItemsControl\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/editor/Stride.Core.Assets.Editor/View/Behaviors/TilePanelThumbnailPrioritizationBehavior.cs","lineNumber":55,"sourceCode":"\n            previousFirstVisibleItemIndex = firstVisibleItemIndex;\n            previousLastVisibleItemIndex = lastVisibleItemIndex;\n\n            var items = AssociatedObject.ItemsSource?.Cast<ISessionObjectViewModel>().ToList();\n            if (items == null || firstVisibleItemIndex > lastVisibleItemIndex)\n                return;\n\n            var session = items[0].Session;\n            var visibleAssets = items.Subset(firstVisibleItemIndex, lastVisibleItemIndex - firstVisibleItemIndex + 1).OfType<AssetViewModel>();\n            session.Thumbnails.IncreaseThumbnailPriority(visibleAssets);\n        }\n\n        private static VirtualizingTilePanel GetItemsPanel(DependencyObject itemsControl)\n        {\n            var itemsPresenter = itemsControl.FindVisualChildOfType<ItemsPresenter>();\n\n            if (itemsPresenter == null)\n                throw new InvalidOperationException(\"Unable to reach the ItemsPresenter of the associated ItemsControl.\");\n\n            var itemsPanel = (VirtualizingTilePanel)VisualTreeHelper.GetChild(itemsPresenter, 0);\n\n            if (itemsPanel == null)\n                throw new InvalidOperationException(\"Unable to reach the VirtualizingTilePanel of the associated ItemsControl.\");\n            return itemsPanel;\n        }\n    }\n}\n","sourceCodeStart":37,"sourceCodeEnd":65,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/editor/Stride.Core.Assets.Editor/View/Behaviors/TilePanelThumbnailPrioritizationBehavior.cs#L37-L65","documentation":"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.","triggerScenarios":"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.","commonSituations":"Attaching the behavior to a collapsed/never-realized ItemsControl; empty items source so the presenter is not instantiated; custom template missing the ItemsPresenter part.","solutions":["Ensure the behavior's loaded handler runs after the template is applied and the panel is realized (hook to ItemsControl.Loaded / ItemContainerGenerator.StatusChanged)","Verify the ItemsControl's ControlTemplate contains an ItemsPresenter","Ensure the ItemsSource has items so the presenter and panel are materialized"],"exampleFix":"// before\nprivate void OnAttachedAndLoaded(object s, RoutedEventArgs e) => GetItemsPanel(AssociatedObject);\n// after\nprivate void OnAttachedAndLoaded(object s, RoutedEventArgs e)\n{\n    if (AssociatedObject.FindVisualChildOfType<ItemsPresenter>() == null)\n        return; // retry on next Loaded / generator status change\n    GetItemsPanel(AssociatedObject);\n}","handlingStrategy":"validation","validationCode":"if (itemsControl.FindVisualChildOfType<ItemsPresenter>() == null)\n    return; // not realized yet; retry on Loaded / ItemContainerGenerator.StatusChanged","typeGuard":"static bool HasItemsPresenter(Visual root) => root.FindVisualChildOfType<ItemsPresenter>() != null;","tryCatchPattern":"try { var panel = GetItemsPanel(itemsControl); }\ncatch (InvalidOperationException) { itemsControl.ItemContainerGenerator.StatusChanged += RetryWhenRealized; }","preventionTips":["Run panel-dependent logic after ItemContainerGenerator emits ItemsRealized","Ensure the ControlTemplate contains an ItemsPresenter","Defer behavior work until the control is loaded and has items"],"tags":["wpf","visual-tree","virtualization"],"backgroundTag":"invalid-state-transition","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}