{"record":{"id":"d0e4ea73d3581081","repo":"stride3d/stride","slug":"a-part-named-listboxpartname-must-be-present-in-the","errorCode":null,"errorMessage":"A part named '{ListBoxPartName}' must be present in the ControlTemplate, and must be of type '{nameof(ListBox)}'.","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/SearchComboBox.cs","lineNumber":155,"sourceCode":"        /// Gets or sets the search text of this <see cref=\"SearchComboBox\"/>\n        /// </summary>\n        public string SearchText { get { return (string)GetValue(SearchTextProperty); } set { SetValue(SearchTextProperty, value); } }\n        /// <summary>\n        /// Gets or sets the content to display when the TextBox is empty.\n        /// </summary>\n        public object WatermarkContent { get { return GetValue(WatermarkContentProperty); } set { SetValue(WatermarkContentProperty, value); } }\n\n        public override void OnApplyTemplate()\n        {\n            base.OnApplyTemplate();\n\n            editableTextBox = GetTemplateChild(EditableTextBoxPartName) as TextBox;\n            if (editableTextBox == null)\n                throw new InvalidOperationException($\"A part named '{EditableTextBoxPartName}' must be present in the ControlTemplate, and must be of type '{typeof(TextBox).FullName}'.\");\n\n            listBox = GetTemplateChild(ListBoxPartName) as ListBox;\n            if (listBox == null)\n                throw new InvalidOperationException($\"A part named '{ListBoxPartName}' must be present in the ControlTemplate, and must be of type '{nameof(ListBox)}'.\");\n            \n            editableTextBox.LostFocus += EditableTextBoxLostFocus;\n            editableTextBox.PreviewKeyDown += EditableTextBoxPreviewKeyDown;\n            editableTextBox.PreviewKeyUp += EditableTextBoxPreviewKeyUp;\n            editableTextBox.Validated += EditableTextBoxValidated;\n            listBox.MouseUp += ListBoxMouseUp;\n        }\n\n        protected override void OnGotKeyboardFocus(KeyboardFocusChangedEventArgs e)\n        {\n            base.OnGotKeyboardFocus(e);\n            if (OpenDropDownOnFocus && !listBoxClicking)\n            {\n                IsDropDownOpen = true;\n            }\n            listBoxClicking = false;\n        }\n","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/presentation/Stride.Core.Presentation.Wpf/Controls/SearchComboBox.cs#L137-L173","documentation":"SearchComboBox.OnApplyTemplate also requires a ListBox part (ListBoxPartName) that hosts filtered results. If the applied ControlTemplate omits it or substitutes another element type, GetTemplateChild returns null and an InvalidOperationException is thrown before the control finishes wiring its event handlers.","triggerScenarios":"Custom ControlTemplate for SearchComboBox without a ListBox named per ListBoxPartName; part renamed or replaced by ItemsControl/ListView.","commonSituations":"Re-templating search combos; partial copies of the default template; designers replacing ListBox with lighter list controls, breaking the required part contract.","solutions":["Add a ListBox named per ListBoxPartName (typically PART_ListBox) to the ControlTemplate","Keep the exact, case-sensitive part name","Use a ListBox specifically — MouseUp handling is attached to it","Start from the default SearchComboBox template and modify incrementally"],"exampleFix":"<!-- before -->\n<ControlTemplate TargetType=\"scb:SearchComboBox\">\n  <Grid>\n    <TextBox x:Name=\"PART_EditableTextBox\"/>\n    <ItemsControl x:Name=\"PART_ListBox\"/>\n  </Grid>\n</ControlTemplate>\n<!-- after -->\n<ControlTemplate TargetType=\"scb:SearchComboBox\">\n  <Grid>\n    <TextBox x:Name=\"PART_EditableTextBox\"/>\n    <ListBox x:Name=\"PART_ListBox\"/>\n  </Grid>\n</ControlTemplate>","handlingStrategy":"validation","validationCode":"var lb = searchComboBox.Template?.FindName(\"PART_ListBox\", searchComboBox) as ListBox;\nif (lb == null) throw new InvalidOperationException(\"SearchComboBox template missing ListBox part\");","typeGuard":"bool HasResultsList(SearchComboBox c) => c.Template?.FindName(\"PART_ListBox\", c) is ListBox;","tryCatchPattern":"try { control.ApplyTemplate(); }\ncatch (InvalidOperationException ex) { log.Error(ex, \"Invalid SearchComboBox template; restoring default style\"); control.Style = null; }","preventionTips":["Keep the ListBox part; do not swap in ItemsControl/ListView","Maintain exact part names from the default template","Validate templates after upgrades and theme refactors","Add ApplyTemplate smoke tests for re-templated controls"],"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"}