{"record":{"id":"526f7cb8a2ba219e","repo":"tui-cs/Terminal.Gui","slug":"content-height-cannot-be-negative","errorCode":null,"errorMessage":"Content height cannot be negative.","messagePattern":"Content height cannot be negative\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Terminal.Gui/ViewBase/View.Content.cs","lineNumber":79,"sourceCode":"    ///         height.\n    ///     </para>\n    ///     <para>\n    ///         If set to a non-<see langword=\"null\"/> value, the content height is independent of the <see cref=\"Viewport\"/>\n    ///         height, enabling vertical scrolling.\n    ///     </para>\n    ///     <para>\n    ///         This method follows the Cancellable Work Pattern (CWP). The <see cref=\"ContentSizeChanging\"/> event\n    ///         is raised before the change, and <see cref=\"ContentSizeChanged\"/> is raised after.\n    ///     </para>\n    /// </remarks>\n    /// <param name=\"contentHeight\">The new content height, or <see langword=\"null\"/> to track the Viewport height.</param>\n    /// <seealso cref=\"SetContentWidth\"/>\n    /// <seealso cref=\"SetContentSize\"/>\n    public void SetContentHeight (int? contentHeight)\n    {\n        if (contentHeight is < 0)\n        {\n            throw new ArgumentException (@\"Content height cannot be negative.\", nameof (contentHeight));\n        }\n\n        ApplyContentDimensionChange (_contentWidth, contentHeight);\n    }\n\n    /// <summary>\n    ///     Sets the size of the View's content.\n    /// </summary>\n    /// <remarks>\n    ///     <para>\n    ///         See the View Layout Deep Dive for more information:\n    ///         <see href=\"https://tui-cs.github.io/Terminal.Gui/docs/layout.html\"/>\n    ///     </para>\n    ///     <para>\n    ///         Negative sizes are not supported.\n    ///     </para>\n    ///     <para>\n    ///         If not explicitly set to a non-<see langword=\"null\"/> value, and the View has Subviews,","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/tui-cs/Terminal.Gui/blob/2e47b11478db083499917f2ad27c34d30efb0df1/Terminal.Gui/ViewBase/View.Content.cs#L61-L97","documentation":"SetContentHeight sets the height of the View's content area independently of the Viewport, enabling vertical scrolling. A negative height is rejected because content cannot occupy negative rows. Pass null to track the Viewport height automatically.","triggerScenarios":"Calling SetContentHeight(-1) or passing a computed height that goes negative (e.g. lineHeight * itemCount where itemCount is -1, or subtracting a header from an uninitialized Viewport).","commonSituations":"Pre-layout content sizing when Viewport is still 0, scroll-offset arithmetic that subtracts too much, using -1 as an 'unset' sentinel.","solutions":["Clamp the computed height to zero minimum.","Pass null to let the height track the Viewport.","Call SetContentSize/Height only after the Viewport is laid out."],"exampleFix":"// before\nview.SetContentHeight(lines * -1);\n// after\nview.SetContentHeight(Math.Max(0, lines));","handlingStrategy":"validation","validationCode":"view.SetContentHeight (h >= 0 ? h : null);","typeGuard":"static bool IsValidContentDim (int? d) => d is null || d >= 0;","tryCatchPattern":null,"preventionTips":["Clamp computed heights to >= 0.","Use null for Viewport-tracking mode.","Defer content sizing until after layout."],"tags":["content","layout","scrolling","validation"],"backgroundTag":null,"analyzedSha":"2e47b11478db083499917f2ad27c34d30efb0df1","analyzedAt":"2026-08-13T19:20:08.826Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}