{"record":{"id":"5d907ce27255ab1e","repo":"stride3d/stride","slug":"a-part-named-messagecontainerpartname-must-be-present-in-the","errorCode":null,"errorMessage":"A part named '{MessageContainerPartName}' must be present in the ControlTemplate, and must be of type '{typeof(FlowDocumentScrollViewer)}'.","messagePattern":"A part named '(.+?)' must be present in the ControlTemplate, and must be of type '(.+?)'\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/presentation/Stride.Core.Presentation.Wpf/Controls/MarkdownTextBlock.cs","lineNumber":92,"sourceCode":"\n        static MarkdownTextBlock()\n        {\n            DefaultStyleKeyProperty.OverrideMetadata(typeof(MarkdownTextBlock), new FrameworkPropertyMetadata(typeof(MarkdownTextBlock)));\n        }\n\n        public MarkdownTextBlock()\n        {\n            defaultMarkdown = new Lazy<XamlMarkdown>(() => new XamlMarkdown(this));\n        }\n\n        /// <inheritdoc/>\n        public override void OnApplyTemplate()\n        {\n            base.OnApplyTemplate();\n\n            messageContainer = GetTemplateChild(MessageContainerPartName) as FlowDocumentScrollViewer;\n            if (messageContainer == null)\n                throw new InvalidOperationException($\"A part named '{MessageContainerPartName}' must be present in the ControlTemplate, and must be of type '{typeof(FlowDocumentScrollViewer)}'.\");\n\n            ResetMessage();\n        }\n\n        private static void BaseUrlChanged([NotNull] DependencyObject d, DependencyPropertyChangedEventArgs e)\n        {\n            var control = d as MarkdownTextBlock;\n            if (control == null) throw new ArgumentNullException(nameof(control));\n\n            if (e.NewValue != null)\n            {\n                control.GetMarkdown().BaseUrl = (string)e.NewValue;\n            }\n            control.ResetMessage();\n        }\n\n        private static void HyperlinkCommandChanged([NotNull] DependencyObject d, DependencyPropertyChangedEventArgs e)\n        {","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/presentation/Stride.Core.Presentation.Wpf/Controls/MarkdownTextBlock.cs#L74-L110","documentation":"MarkdownTextBlock.OnApplyTemplate fetches the mandatory template part 'PART_MessageContainer' and requires it to be a FlowDocumentScrollViewer. When the applied ControlTemplate is missing that part (or names it differently / uses another element type), GetTemplateChild returns null and an InvalidOperationException is thrown.","triggerScenarios":"Applying a custom ControlTemplate for MarkdownTextBlock that omits the part named by MessageContainerPartName, names it incorrectly, or hosts an element that is not a FlowDocumentScrollViewer.","commonSituations":"Re-templating the control for theming; upgrading Stride and copying an outdated template; hand-written Styles without the required part; renaming the part x:Name in XAML.","solutions":["Add <FlowDocumentScrollViewer x:Name=\"PART_MessageContainer\"/> to the ControlTemplate","Verify the part name matches MessageContainerPartName exactly (case-sensitive)","Ensure the part element is a FlowDocumentScrollViewer, not a subclass-less substitute like ContentPresenter","Base your custom template on the library's default template for MarkdownTextBlock"],"exampleFix":"<!-- before -->\n<ControlTemplate TargetType=\"mtb:MarkdownTextBlock\">\n  <Border Background=\"Transparent\"/>\n</ControlTemplate>\n<!-- after -->\n<ControlTemplate TargetType=\"mtb:MarkdownTextBlock\">\n  <Border Background=\"Transparent\">\n    <FlowDocumentScrollViewer x:Name=\"PART_MessageContainer\"/>\n  </Border>\n</ControlTemplate>","handlingStrategy":"validation","validationCode":"// validate template parts before/after ApplyTemplate in your hosting code\nvar container = markdownTextBlock.Template?.FindName(\"PART_MessageContainer\", markdownTextBlock) as FlowDocumentScrollViewer;\nif (container == null) throw new InvalidOperationException(\"Custom MarkdownTextBlock template is missing PART_MessageContainer (FlowDocumentScrollViewer)\");","typeGuard":"bool HasValidMarkdownTemplate(MarkdownTextBlock c) => c.Template?.FindName(\"PART_MessageContainer\", c) is FlowDocumentScrollViewer;","tryCatchPattern":"try { control.ApplyTemplate(); }\ncatch (InvalidOperationException ex) { log.Error(ex, \"Invalid MarkdownTextBlock template; falling back to default style\"); control.Style = null; }","preventionTips":["Never remove PART_-prefixed elements when re-templating","Keep part names and types identical to the default template","Test custom templates by forcing ApplyTemplate in unit tests","Copy templates from the same library version you reference"],"tags":["wpf","controltemplate","xaml"],"backgroundTag":"schema-validation-failed","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}