{"record":{"id":"eb328e04c1368785","repo":"dotnet/wpf","slug":"sr-flowdocumentscrollviewer","errorCode":null,"errorMessage":"SR.FlowDocumentScrollViewerMarkedAsContentHostMustHaveNoContent","messagePattern":"SR\\.FlowDocumentScrollViewerMarkedAsContentHostMustHaveNoContent","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/FlowDocumentScrollViewer.cs","lineNumber":124,"sourceCode":"            _toolBarHost?.Visibility = IsToolBarVisible ? Visibility.Visible : Visibility.Collapsed;\n\n            // Initialize ContentHost.\n            // If old ContentHost is enabled, disable it first to ensure appropriate cleanup.\n            if (_contentHost != null)\n            {\n                BindingOperations.ClearBinding(_contentHost, HorizontalScrollBarVisibilityProperty);\n                BindingOperations.ClearBinding(_contentHost, VerticalScrollBarVisibilityProperty);\n                _contentHost.ScrollChanged -= new ScrollChangedEventHandler(OnScrollChanged);\n                RenderScope.Document = null;\n                ClearValue(TextEditor.PageHeightProperty);\n                _contentHost.Content = null;\n            }\n            _contentHost = GetTemplateChild(_contentHostTemplateName) as ScrollViewer;\n            if (_contentHost != null)\n            {\n                if (_contentHost.Content != null)\n                {\n                    throw new NotSupportedException(SR.FlowDocumentScrollViewerMarkedAsContentHostMustHaveNoContent);\n                }\n                _contentHost.ScrollChanged += new ScrollChangedEventHandler(OnScrollChanged);\n                CreateTwoWayBinding(_contentHost, HorizontalScrollBarVisibilityProperty, \"HorizontalScrollBarVisibility\");\n                CreateTwoWayBinding(_contentHost, VerticalScrollBarVisibilityProperty, \"VerticalScrollBarVisibility\");\n\n                // Need to make ScrollViewer non-focusable, otherwise it will eat keyboard navigation from editor.\n                _contentHost.Focusable = false;\n\n                // Initialize the content of the ScrollViewer.\n                _contentHost.Content = new FlowDocumentView();\n                RenderScope.Document = Document;\n            }\n\n            // Initialize TextEditor.\n            AttachTextEditor();\n\n            // Apply the current zoom to the content host.\n            ApplyZoom();","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/FlowDocumentScrollViewer.cs#L106-L142","documentation":"FlowDocumentScrollViewer.OnApplyTemplate throws this NotSupportedException when the template part named as the content host (PART_ContentHost, a ScrollViewer) is found but already has Content set. The content host part is reserved for the viewer's internal document presenter; user-supplied content in it would break the viewer's scrolling/layout wiring.","triggerScenarios":"Applying a custom ControlTemplate for FlowDocumentScrollViewer whose PART_ContentHost ScrollViewer element has child content (e.g. extra elements inside the ScrollViewer).","commonSituations":"Custom restyling of FlowDocumentScrollViewer where developers add decorations or wrappers inside the content host part; copying a template from another control and leaving content in the part.","solutions":["Remove all content from the PART_ContentHost ScrollViewer in your ControlTemplate; keep it empty.","If you need extra visuals, place them outside the content host part or in other template parts.","Start from the default FlowDocumentScrollViewer template and only modify elements other than the content host."],"exampleFix":"<!-- before: throws -->\n<ScrollViewer x:Name=\"PART_ContentHost\">\n  <Border Background=\"Beige\"/>\n</ScrollViewer>\n\n<!-- after -->\n<ScrollViewer x:Name=\"PART_ContentHost\"/>\n<Border Background=\"Beige\"/> <!-- moved outside the host -->","handlingStrategy":"validation","validationCode":"// In your custom template review step:\nvar host = template.FindName(\"PART_ContentHost\", templatedParent) as ScrollViewer;\nif (host != null && host.Content != null)\n    throw new InvalidOperationException(\"PART_ContentHost must have no content.\");","typeGuard":null,"tryCatchPattern":"try { viewer.ApplyTemplate(); }\ncatch (NotSupportedException ex) { logger.Error(ex); LoadDefaultTemplate(); }","preventionTips":["Keep PART_ContentHost empty in custom ControlTemplates.","Derive custom templates from the default FlowDocumentScrollViewer template.","Test template changes with OnApplyTemplate early, not only in production."],"tags":["wpf","flowdocumentscrollviewer","template","invalid-config-value"],"backgroundTag":"invalid-config-value","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}