stride3d/stride · error · InvalidOperationException
BringItemToView cannot be used when the tree view is…
Error message
BringItemToView cannot be used when the tree view is virtualizing.
What it means
BringItemToView scrolls a TreeView so a given item is visible by walking parent containers to realize them. This only works with container generation that is not virtualized; when VirtualizingPanel.IsVirtualizing is true, containers for off-screen items do not exist and cannot be generated by this method, so the control throws InvalidOperationException up front instead of failing silently.
Solutions
- Set VirtualizingPanel.IsVirtualizing="False" on the TreeView (accepting the performance cost).
- Remove/disable the BringItemToView call and instead use container-free navigation (e.g. expand path via the view-model then rely on selection scrolling).
- Guard the call: check treeView.IsVirtualizing (or the attached property) before invoking and take an alternate path.
Example fix
// before
treeView.BringItemToView(node, n => vm.GetParent(n));
// after
if (!treeView.IsVirtualizing)
treeView.BringItemToView(node, n => vm.GetParent(n));
else
ExpandPathTo(node); // expand ancestors so the container is realized Defensive patterns
Strategy: validation
Validate before calling
if (treeView.IsVirtualizing)
throw new NotSupportedException("BringItemToView requires a non-virtualizing TreeView");
treeView.BringItemToView(item, parent => vm.GetParent(parent)); Type guard
bool CanBringToView(TreeView tv) => !tv.IsVirtualizing;
Try / catch
try { treeView.BringItemToView(item, getParent); }
catch (InvalidOperationException ex) when (ex.Message.Contains("virtualizing")) { ExpandPathTo(item); /* fallback */ } Prevention
- Check IsVirtualizing before any programmatic scroll-to-item logic.
- If virtualization is on, expand ancestors via the view-model instead of container walking.
- Document the virtualization constraint next to any shared BringItemToView helper.
When it happens
Trigger: Calling treeView.BringItemToView(item, getParent) on a TreeView whose virtualization is enabled (VirtualizingPanel.IsVirtualizing=true, e.g. inside a large list with VirtualizingStackPanel), passing non-null item and getParent.
Common situations: Programmatic navigation/selection restore in editor-like trees; code written for a non-virtualized tree later moved into a virtualized layout; enabling virtualization for performance on large trees and existing BringItemToView calls start throwing.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Unable to reach the ItemsPresenter of the associated…
- SelectionMode.Multiple is not yet supported. Please use…
- Can only change SelectedItems collection in multiple…
- Width must not be infinite when virtualizing vertically.
- Height must not be infinite when virtualizing horizontally.
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/d756fe58aa40b8d0.
Report an issue: GitHub.
Appendix: source
Thrown at sources/presentation/Stride.Core.Presentation.Wpf/Controls/TreeView.cs:158
{
base.OnApplyTemplate();
scroller = DependencyObjectExtensions.CheckTemplatePart<ScrollViewer>(GetTemplateChild(ScrollViewerPartName));
if (scroller != null)
{
scroller.ScrollChanged += ScrollChanged;
}
}
// TODO: This method has been implemented with a lot of fail and retry, and should be cleaned.
// TODO: Also, it is probably close to work with virtualization, but it needs some testing
public bool BringItemToView([NotNull] object item, [NotNull] Func<object, object> getParent)
{
// Useful link: https://msdn.microsoft.com/en-us/library/ff407130%28v=vs.110%29.aspx
if (item == null) throw new ArgumentNullException(nameof(item));
if (getParent == null) throw new ArgumentNullException(nameof(getParent));
if (IsVirtualizing)
throw new InvalidOperationException("BringItemToView cannot be used when the tree view is virtualizing.");
TreeViewItem container = null;
var path = new List<object> { item };
var parent = getParent(item);
while (parent != null)
{
path.Add(parent);
parent = getParent(parent);
}
for (var i = path.Count - 1; i >= 0; --i)
{
if (container != null)
container = (TreeViewItem)container.ItemContainerGenerator.ContainerFromItem(path[i]);
else
container = (TreeViewItem)ItemContainerGenerator.ContainerFromItem(path[i]);
View on GitHub (pinned to 96fad776d2)