{"record":{"id":"f1ef5f6e66e63e60","repo":"stride3d/stride","slug":"a-part-named-part-trimmedtext-must-be-present-in-the","errorCode":null,"errorMessage":"A part named 'PART_TrimmedText' must be present in the ControlTemplate, and must be of type 'TextBlock'.","messagePattern":"A part named 'PART_TrimmedText' must be present in the ControlTemplate, and must be of type 'TextBlock'\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/presentation/Stride.Core.Presentation.Wpf/Controls/TextBox.cs","lineNumber":85,"sourceCode":"        /// Gets or sets the amount of time before a validation of input text happens, in milliseconds.\n        /// Every change to the <see cref=\"TextBox.Text\"/> property reset the timer to this value.\n        /// </summary>\n        /// <remarks>The default value is <c>500</c> milliseconds.</remarks>\n        public int ValidationDelay { get { return (int)GetValue(ValidationDelayProperty); } set { SetValue(ValidationDelayProperty, value); } }\n        \n        /// <summary>\n        /// Gets the trimmed text to display when the control does not have the focus, depending of the value of the <see cref=\"TextTrimming\"/> property.\n        /// </summary>\n        public string TrimmedText { get { return (string)GetValue(TrimmedTextPropertyKey.DependencyProperty); } private set { SetValue(TrimmedTextPropertyKey, value); } }\n\n        /// <inheritdoc/>\n        public override void OnApplyTemplate()\n        {\n            base.OnApplyTemplate();\n\n            trimmedTextBlock = GetTemplateChild(\"PART_TrimmedText\") as TextBlock;\n            if (trimmedTextBlock == null)\n                throw new InvalidOperationException(\"A part named 'PART_TrimmedText' must be present in the ControlTemplate, and must be of type 'TextBlock'.\");\n        }\n\n        /// <summary>\n        /// Raised when the text of the TextBox changes.\n        /// </summary>\n        /// <param name=\"oldValue\">The old value of the <see cref=\"TextBox.Text\"/> property.</param>\n        /// <param name=\"newValue\">The new value of the <see cref=\"TextBox.Text\"/> property.</param>\n        protected override void OnTextChanged(string oldValue, string newValue)\n        {\n            if (UseTimedValidation)\n            {\n                if (ValidationDelay > 0.0)\n                {\n                    validationTimer?.Change(ValidationDelay, Timeout.Infinite);\n                }\n                else\n                {\n                    Validate();","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/presentation/Stride.Core.Presentation.Wpf/Controls/TextBox.cs#L67-L103","documentation":"The Stride TextBox custom control requires its ControlTemplate to contain a named part 'PART_TrimmedText' of type TextBlock, used to render a trimmed/ellipsis version of the text. During OnApplyTemplate the control looks this part up via GetTemplateChild; if the template omits it or provides a different element type, the cast yields null and the control throws InvalidOperationException. This enforces the WPF template-part contract so the control's visual logic always has the elements it depends on.","triggerScenarios":"Applying a custom ControlTemplate to this TextBox control that lacks an element named 'PART_TrimmedText', or names it but the element is not a TextBlock (e.g. a Border or ContentPresenter). Also triggered when the default template resource fails to load so OnApplyTemplate runs against an empty/partial template.","commonSituations":"Developers restyling the control with a new Style/ControlTemplate and forgetting to copy required named parts; renaming the part in a copied template; theming resources missing after a library upgrade.","solutions":["Add <TextBlock x:Name=\"PART_TrimmedText\"/> to the custom ControlTemplate.","Ensure the element named PART_TrimmedText is a TextBlock, not another element type.","If not customizing visuals, remove the custom Style so the library's default template is used."],"exampleFix":"// before (custom template missing part)\n<Style TargetType=\"controls:TextBox\">\n  <Setter Property=\"Template\">\n    <Setter.Value>\n      <ControlTemplate TargetType=\"controls:TextBox\">\n        <Border><ScrollViewer x:Name=\"PART_ContentHost\"/></Border>\n      </ControlTemplate>\n    </Setter.Value>\n  </Setter>\n</Style>\n// after\n<ControlTemplate TargetType=\"controls:TextBox\">\n  <Border>\n    <ScrollViewer x:Name=\"PART_ContentHost\"/>\n    <TextBlock x:Name=\"PART_TrimmedText\" TextTrimming=\"CharacterEllipsis\"/>\n  </Border>\n</ControlTemplate>","handlingStrategy":"validation","validationCode":"// In template resource review, assert required parts exist before applying:\nvar tb = template.FindName(\"PART_TrimmedText\", templatedParentScope) as TextBlock;\nif (tb == null) throw new InvalidOperationException(\"Template must contain TextBlock named PART_TrimmedText\");","typeGuard":"bool HasTrimmedTextPart(ControlTemplate t, FrameworkElement scope) =>\n    scope != null && scope.FindName(\"PART_TrimmedText\", scope) is TextBlock;","tryCatchPattern":"try { element.ApplyTemplate(); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"PART_TrimmedText\")) { /* restore default template or log template contract violation */ }","preventionTips":["When copying a default template, diff it against the original to keep all PART_ named parts.","Add a unit/style smoke test that instantiates the control and calls ApplyTemplate with your custom template.","Never rename PART_* parts in custom templates; they are a public contract."],"tags":["wpf","control-template","template-parts"],"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-15T23:17:13.987Z"}