{"record":{"id":"7606d3bb62cd8030","repo":"dotnet/wpf","slug":"sr","errorCode":null,"errorMessage":"SR.FlowDocumentReaderDecoratorMarkedAsContentHostMustHaveNoContent","messagePattern":"SR\\.FlowDocumentReaderDecoratorMarkedAsContentHostMustHaveNoContent","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/FlowDocumentReader.cs","lineNumber":98,"sourceCode":"        /// Build Visual tree\n        /// </summary>\n        public override void OnApplyTemplate()\n        {\n            base.OnApplyTemplate();\n\n            // Initialize ContentHost.\n            // If old ContentHost is enabled, disable it first to ensure appropriate cleanup.\n            if (CurrentViewer != null)\n            {\n                DetachViewer(CurrentViewer);\n                _contentHost.Child = null;\n            }\n            _contentHost = GetTemplateChild(_contentHostTemplateName) as Decorator;\n            if (_contentHost != null)\n            {\n                if (_contentHost.Child != null)\n                {\n                    throw new NotSupportedException(SR.FlowDocumentReaderDecoratorMarkedAsContentHostMustHaveNoContent);\n                }\n\n                SwitchViewingModeCore(ViewingMode);\n            }\n\n            // Initialize FindTooBar host.\n            // If old FindToolBar is enabled, disable it first to ensure appropriate cleanup.\n            if (FindToolBar != null)\n            {\n                ToggleFindToolBar(false);\n            }\n            _findToolBarHost = GetTemplateChild(_findToolBarHostTemplateName) as Decorator;\n            _findButton = GetTemplateChild(_findButtonTemplateName) as ToggleButton;\n        }\n\n        /// <summary>\n        /// Whether the master page can be moved to the specified page.\n        /// </summary>","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/FlowDocumentReader.cs#L80-L116","documentation":"FlowDocumentReader's template marks a Decorator as its content host; OnApplyTemplate requires that this Decorator has no child of its own. If the template author placed content inside the ContentHost Decorator, NotSupportedException (SR.FlowDocumentReaderDecoratorMarkedAsContentHostMustHaveNoContent) is thrown because the reader needs to install its own content there.","triggerScenarios":"Custom ControlTemplate for FlowDocumentReader where the Decorator named as ContentHost (PART_ContentHost) contains child elements; copying the default template and adding decorations inside the content host.","commonSituations":"Restyling FlowDocumentReader to add borders/overlays directly inside the content-host Decorator.","solutions":["Remove any children from the ContentHost Decorator in the template","Place additional visuals outside the ContentHost Decorator (e.g. in an outer Grid)","Start from the default FlowDocumentReader template and keep the content host empty"],"exampleFix":"// before\n<Decorator Name=\"PART_ContentHost\">\n  <Border Background=\"LightGray\"/>\n</Decorator>\n// after\n<Grid>\n  <Decorator Name=\"PART_ContentHost\"/>\n</Grid>","handlingStrategy":"validation","validationCode":"var host = template.FindName(\"PART_ContentHost\", reader) as Decorator;\nbool ok = host == null || host.Child == null;","typeGuard":null,"tryCatchPattern":"try { reader.ApplyTemplate(); }\ncatch (NotSupportedException) { /* ContentHost decorator has content */ }","preventionTips":["Keep the content-host Decorator childless in templates","Put extra visuals in outer containers, not inside the host","Re-test custom FlowDocumentReader templates after edits"],"tags":["wpf","flowdocumentreader","template","not-supported"],"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-21T21:30:21.729Z"}