{"record":{"id":"bd8cf535592ac66e","repo":"stride3d/stride","slug":"height-must-not-be-infinite-when-virtualizing-horizontally","errorCode":null,"errorMessage":"Height must not be infinite when virtualizing horizontally.","messagePattern":"Height must not be infinite when virtualizing horizontally\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/presentation/Stride.Core.Presentation.Wpf/Controls/VirtualizingTilePanel.cs","lineNumber":169,"sourceCode":"            ItemCount = parentItemsControl.Items.Count;\n            ItemsPerLine = ItemCount;\n            lineCount = ItemsPerLine;\n\n            Size desiredSize;\n            if (Orientation == Orientation.Vertical)\n            {\n                if (double.IsPositiveInfinity(availableSize.Width))\n                    throw new InvalidOperationException(\"Width must not be infinite when virtualizing vertically.\");\n\n                ItemsPerLine = (int)Math.Ceiling(availableSize.Width - MinimumItemSpacing) / (int)(ItemSlotSize.Width + MinimumItemSpacing);\n                ItemsPerLine = Math.Max(1, Math.Min(ItemsPerLine, ItemCount));\n                lineCount = ComputeLineCount(ItemCount);\n                desiredSize = new Size(availableSize.Width, lineCount * ItemSlotSize.Height);\n            }\n            else\n            {\n                if (double.IsPositiveInfinity(availableSize.Height))\n                    throw new InvalidOperationException(\"Height must not be infinite when virtualizing horizontally.\");\n\n                ItemsPerLine = (int)Math.Ceiling(availableSize.Height - MinimumItemSpacing) / (int)Math.Ceiling(ItemSlotSize.Height + MinimumItemSpacing);\n                ItemsPerLine = Math.Max(1, Math.Min(ItemsPerLine, ItemCount));\n                lineCount = ComputeLineCount(ItemCount);\n                desiredSize = new Size(lineCount * ItemSlotSize.Width, availableSize.Height);\n            }\n\n            UpdateScrollInfo(availableSize);\n\n            int firstVisibleItemIndex, lastVisibleItemIndex;\n            GetVisibilityRange(availableSize, out firstVisibleItemIndex, out lastVisibleItemIndex);\n\n            // Get the generator position of the first visible data item\n            var startPos = generator.GeneratorPositionFromIndex(firstVisibleItemIndex);\n\n            var childIndex = (startPos.Offset == 0) ? startPos.Index : startPos.Index + 1;\n\n            using (generator.StartAt(startPos, GeneratorDirection.Forward, true))","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/presentation/Stride.Core.Presentation.Wpf/Controls/VirtualizingTilePanel.cs#L151-L187","documentation":"When VirtualizingTilePanel is oriented horizontally, MeasureOverride requires a finite available height to determine items per line. If availableSize.Height is PositiveInfinity the line layout for virtualization cannot be computed, so the panel throws InvalidOperationException rather than producing incorrect virtualization.","triggerScenarios":"A horizontally-oriented VirtualizingTilePanel measured with infinite height: inside a vertical StackPanel, a ScrollViewer with VerticalScrollBarVisibility=Auto, or an unconstrained Grid Auto row.","commonSituations":"Vertical StackPanel wrapper around a horizontal tile list; auto-sized rows/cells; forgetting to set Height or VerticalAlignment when embedding the panel.","solutions":["Constrain height: set explicit Height or use VerticalAlignment=\"Stretch\" in a Grid.","Replace the enclosing vertical StackPanel with a Grid/DockPanel that supplies a finite height.","Scroll horizontally within a fixed-height viewport instead of letting height be unbounded."],"exampleFix":"// before\n<StackPanel>\n  <controls:VirtualizingTilePanel Orientation=\"Horizontal\"/>\n</StackPanel>\n// after\n<Grid>\n  <controls:VirtualizingTilePanel Orientation=\"Horizontal\" VerticalAlignment=\"Stretch\"/>\n</Grid>","handlingStrategy":"validation","validationCode":"// Ensure a finite height constraint for horizontal orientation:\ntilePanel.Height = double.IsInfinity(desiredHeight) ? 400 : desiredHeight;\n// or host in a Grid with VerticalAlignment=Stretch.","typeGuard":"bool HasFiniteHeightConstraint(FrameworkElement el) =>\n    !double.IsPositiveInfinity(el.Height) || el.VerticalAlignment == VerticalAlignment.Stretch;","tryCatchPattern":"try { panelHost.UpdateLayout(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Height must not be infinite\")) { tilePanel.Height = 400; tilePanel.UpdateLayout(); }","preventionTips":["Never place horizontally-oriented virtualizing tile panels inside vertical StackPanels.","Use Grid rows with fixed/star sizes rather than Auto when hosting the panel.","Check ancestor ScrollViewers for vertical auto-scroll settings that yield infinite height."],"tags":["wpf","layout","virtualization","measure"],"backgroundTag":"invalid-config-value","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}