stride3d/stride · error · InvalidOperationException

A part named ' ' must be present in the ControlTemplate…

Error message

A part named '{EditableTextBoxPartName}' must be present in the ControlTemplate, and must be of type '{typeof(TextBox).FullName}'.

What it means

SearchComboBox.OnApplyTemplate fetches its editable TextBox part (EditableTextBoxPartName) and throws InvalidOperationException if it is absent or not a TextBox, since search-as-you-type behavior depends on that control.

Solutions

  1. Add a TextBox named per EditableTextBoxPartName (typically PART_EditableTextBox) to the ControlTemplate
  2. Match the part name exactly and case-sensitively
  3. Use a real TextBox element (search/keyboard handling attaches to it)
  4. Base the template on the default SearchComboBox template

Example fix

<!-- before -->
<ControlTemplate TargetType="scb:SearchComboBox">
  <ToggleButton x:Name="PART_ToggleButton"/>
</ControlTemplate>
<!-- after -->
<ControlTemplate TargetType="scb:SearchComboBox">
  <Grid>
    <ToggleButton x:Name="PART_ToggleButton"/>
    <TextBox x:Name="PART_EditableTextBox"/>
  </Grid>
</ControlTemplate>
Defensive patterns

Strategy: validation

Validate before calling

var tb = searchComboBox.Template?.FindName("PART_EditableTextBox", searchComboBox) as TextBox;
if (tb == null) throw new InvalidOperationException("SearchComboBox template missing editable TextBox part");

Type guard

bool HasEditableTextBox(SearchComboBox c) => c.Template?.FindName("PART_EditableTextBox", c) is TextBox;

Try / catch

try { control.ApplyTemplate(); }
catch (InvalidOperationException ex) { log.Error(ex, "Invalid SearchComboBox template; restoring default style"); control.Style = null; }

Prevention

When it happens

Trigger: Applying a custom ControlTemplate for SearchComboBox missing the editable TextBox part; wrong x:Name; using a non-TextBox element such as TextBlock.

Common situations: Re-templating combo boxes for theming; templates copied from stock ComboBox where the part is named PART_EditableTextBox differently; trimming template parts deemed unnecessary.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/1092dd7e98dfa6c3. Report an issue: GitHub.

Appendix: source

Thrown at sources/presentation/Stride.Core.Presentation.Wpf/Controls/SearchComboBox.cs:151

        /// Gets or sets whether the drop down is open.
        /// </summary>
        public bool IsDropDownOpen { get { return (bool)GetValue(IsDropDownOpenProperty); } set { SetValue(IsDropDownOpenProperty, value.Box()); } }
        /// <summary>
        /// Gets or sets the search text of this <see cref="SearchComboBox"/>
        /// </summary>
        public string SearchText { get { return (string)GetValue(SearchTextProperty); } set { SetValue(SearchTextProperty, value); } }
        /// <summary>
        /// Gets or sets the content to display when the TextBox is empty.
        /// </summary>
        public object WatermarkContent { get { return GetValue(WatermarkContentProperty); } set { SetValue(WatermarkContentProperty, value); } }

        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            editableTextBox = GetTemplateChild(EditableTextBoxPartName) as TextBox;
            if (editableTextBox == null)
                throw new InvalidOperationException($"A part named '{EditableTextBoxPartName}' must be present in the ControlTemplate, and must be of type '{typeof(TextBox).FullName}'.");

            listBox = GetTemplateChild(ListBoxPartName) as ListBox;
            if (listBox == null)
                throw new InvalidOperationException($"A part named '{ListBoxPartName}' must be present in the ControlTemplate, and must be of type '{nameof(ListBox)}'.");
            
            editableTextBox.LostFocus += EditableTextBoxLostFocus;
            editableTextBox.PreviewKeyDown += EditableTextBoxPreviewKeyDown;
            editableTextBox.PreviewKeyUp += EditableTextBoxPreviewKeyUp;
            editableTextBox.Validated += EditableTextBoxValidated;
            listBox.MouseUp += ListBoxMouseUp;
        }

        protected override void OnGotKeyboardFocus(KeyboardFocusChangedEventArgs e)
        {
            base.OnGotKeyboardFocus(e);
            if (OpenDropDownOnFocus && !listBoxClicking)
            {
                IsDropDownOpen = true;

View on GitHub (pinned to 96fad776d2)