{"record":{"id":"53c61beae7e0afa7","repo":"dotnet/wpf","slug":"sr-textboxdecoratormarkedastextboxcontentmusthavenocontent","errorCode":null,"errorMessage":"SR.TextBoxDecoratorMarkedAsTextBoxContentMustHaveNoContent","messagePattern":"SR\\.TextBoxDecoratorMarkedAsTextBoxContentMustHaveNoContent","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/TextBoxBase.cs","lineNumber":1915,"sourceCode":"                {\n                    _renderScope = null;\n                    _textBoxContentHost = null;\n                    //  Do not throw exception\n                    throw new NotSupportedException(SR.TextBoxScrollViewerMarkedAsTextBoxContentMustHaveNoContent);\n                }\n                else\n                {\n                    scrollViewer.Content = _renderScope; // this may replace old render scope in case of upgrade scenario in TextBox\n                }\n            }\n            else if (_textBoxContentHost is Decorator decorator)\n            {\n                if (decorator.Child != null)\n                {\n                    _renderScope = null;\n                    _textBoxContentHost = null;\n                    //  Do not throw exception\n                    throw new NotSupportedException(SR.TextBoxDecoratorMarkedAsTextBoxContentMustHaveNoContent);\n                }\n                else\n                {\n                    decorator.Child = _renderScope; // this may replace old render scope in case of upgrade scenario in TextBox\n                }\n            }\n            else\n            {\n                // When we implement TextContainer setting via TextView interface\n                // all text containing element will become allowed here.\n                _renderScope = null;\n\n                // Explicitly not throwing an exception here when content host = null\n                // -- designers need us to support no content scenarios\n                if (_textBoxContentHost != null)\n                {\n                    _textBoxContentHost = null;\n                    //  Remove the exception","sourceCodeStart":1897,"sourceCodeEnd":1933,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/TextBoxBase.cs#L1897-L1933","documentation":"Same contract as the ScrollViewer case but for a Decorator part (e.g. a Border) marked as the TextBox content host: if Decorator.Child is already non-null, TextBoxBase cannot insert its render scope and throws NotSupportedException. The content-host Decorator must be empty at template application time.","triggerScenarios":"Custom TextBox ControlTemplate whose content-host Decorator (e.g. a Border) already has a Child element set in XAML or code before the template is applied.","commonSituations":"Templates that wrap the content host in a Border and also put placeholder/label text inside that same Border instead of a sibling element.","solutions":["Remove the Decorator's Child and let TextBoxBase set it; place watermarks or overlays as siblings in the parent panel.","Verify the content-host part has the correct part name and contains no children in the template.","Start from the default template (copy via Expression Blend / template extraction) and modify only visuals."],"exampleFix":"// before\n<Border>\n    <TextBlock Text=\"placeholder\"/> <!-- Decorator.Child set -> throws -->\n</Border>\n// after\n<Grid>\n    <Border/>\n    <TextBlock Text=\"placeholder\" IsHitTestVisible=\"False\"/>\n</Grid>","handlingStrategy":"validation","validationCode":"bool decoratorIsEmpty = decoratorPart == null || decoratorPart.Child == null;\nif (decoratorIsEmpty) textBox.ApplyTemplate(); // safe to apply template with empty content-host Decorator","typeGuard":"static bool IsValidDecoratorHost(Decorator d) => d != null && d.Child == null;","tryCatchPattern":"try\n{\n    textBox.ApplyTemplate();\n}\ncatch (NotSupportedException)\n{\n    // template misdeclares content host; log template name and fall back to default\n}","preventionTips":["Keep the content-host Decorator childless","Move placeholder visuals to sibling panels","Verify part names match PART_ContentHost exactly"],"tags":["wpf","textbox","template","not-supported"],"backgroundTag":"invalid-argument-value","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}