stride3d/stride · error · InvalidOperationException

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

Error message

A part named 'PART_ListBox' must be present in the ControlTemplate, and must be of type 'ListBox'.

What it means

FilteringComboBox.OnApplyTemplate also requires a template part named 'PART_ListBox' of type ListBox, used to display filtered results and wire selection handling. If GetTemplateChild('PART_ListBox') returns null or a non-ListBox, the control throws InvalidOperationException. This error fires after the PART_EditableTextBox check passes.

Solutions

  1. Add an element named PART_ListBox of type ListBox to the ControlTemplate.
  2. If a custom list type is used, make it derive from ListBox or switch back to ListBox.
  3. Start from the default FilteringComboBox template in the theme and modify incrementally.

Example fix

<!-- before -->
<ItemsControl x:Name="PART_ListBox"/>
<!-- after -->
<ListBox x:Name="PART_ListBox"/>
Defensive patterns

Strategy: validation

Validate before calling

var lb = combo.Template?.FindName("PART_ListBox", combo);
if (lb is not System.Windows.Controls.ListBox)
    throw new InvalidOperationException("Template needs a ListBox named PART_ListBox.");

Type guard

bool HasListBoxPart(FilteringComboBox combo) => combo.Template?.FindName("PART_ListBox", combo) is System.Windows.Controls.ListBox;

Try / catch

try { combo.ApplyTemplate(); }
catch (InvalidOperationException ex) { log.Error("FilteringComboBox template missing PART_ListBox", ex); }

Prevention

When it happens

Trigger: Applying a ControlTemplate for FilteringComboBox containing PART_EditableTextBox but missing an element named PART_ListBox, or where the name is on a different control type (e.g. ItemsControl, ComboBox).

Common situations: Hand-written templates omitting the results list; renaming the part; using a derived/custom list control that doesn't derive from ListBox.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at sources/presentation/Stride.Core.Presentation.Wpf/Controls/FilteringComboBox.cs:244

        {
            var filteringComboBox = (FilteringComboBox)d;
            if (filteringComboBox.ItemsSource != null)
            {
                filteringComboBox.UpdateCollectionView();
            }
        }

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

            editableTextBox = GetTemplateChild("PART_EditableTextBox") as TextBox;
            if (editableTextBox == null)
                throw new InvalidOperationException("A part named 'PART_EditableTextBox' must be present in the ControlTemplate, and must be of type 'Stride.Core.Presentation.Controls.Input.TextBox'.");

            listBox = GetTemplateChild("PART_ListBox") as ListBox;
            if (listBox == null)
                throw new InvalidOperationException("A part named 'PART_ListBox' must be present in the ControlTemplate, and must be of type 'ListBox'.");

            editableTextBox.TextChanged += EditableTextBoxTextChanged;
            editableTextBox.PreviewKeyDown += EditableTextBoxPreviewKeyDown;
            editableTextBox.Validating += EditableTextBoxValidating;
            editableTextBox.Validated += EditableTextBoxValidated;
            editableTextBox.Cancelled += EditableTextBoxCancelled;
            editableTextBox.LostFocus += EditableTextBoxLostFocus;
            listBox.MouseUp += ListBoxMouseUp;
        }

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

View on GitHub (pinned to 96fad776d2)