{"record":{"id":"622b12e70b616103","repo":"MahApps/MahApps.Metro","slug":"template-part-templatepart-in-template-for-t","errorCode":null,"errorMessage":"Template part \"{templatePart}\" in template for \"{target.GetType().FullName}\" is missing.","messagePattern":"Template part \"(.+?)\" in template for \"(.+?)\" is missing\\.","errorType":"exception","errorClass":"MissingRequiredTemplatePartException","httpStatus":null,"severity":"error","filePath":"src/MahApps.Metro/Controls/MultiSelectionComboBox/MultiSelectionComboBox.cs","lineNumber":1190,"sourceCode":"            if (sender is MultiSelectionComboBox)\n            {\n                e.CanExecute = e.Parameter != null;\n            }\n        }\n\n        #endregion\n\n        #region Overrides\n\n        public override void OnApplyTemplate()\n        {\n            this.StopListeningForSelectionChanges();\n\n            base.OnApplyTemplate();\n\n            // Init SelectedItemsPresenter\n            var selectedItemsPresenterName = nameof(this.PART_SelectedItemsPresenter);\n            this.PART_SelectedItemsPresenter = this.GetTemplateChild(selectedItemsPresenterName) as ListBox ?? throw new MissingRequiredTemplatePartException(this, selectedItemsPresenterName);\n\n            this.PART_SelectedItemsPresenter.MouseLeftButtonUp -= this.PART_SelectedItemsPresenter_MouseLeftButtonUp;\n            this.PART_SelectedItemsPresenter.MouseLeftButtonUp += this.PART_SelectedItemsPresenter_MouseLeftButtonUp;\n            this.PART_SelectedItemsPresenter.SelectionChanged -= this.PART_SelectedItemsPresenter_SelectionChanged;\n            this.PART_SelectedItemsPresenter.SelectionChanged += this.PART_SelectedItemsPresenter_SelectionChanged;\n\n            // Init EditableTextBox\n            this.PART_EditableTextBox = this.GetTemplateChild(nameof(this.PART_EditableTextBox)) as TextBox ?? throw new MissingRequiredTemplatePartException(this, nameof(this.PART_EditableTextBox));\n\n            this.PART_EditableTextBox.LostFocus -= this.PART_EditableTextBox_LostFocus;\n            this.PART_EditableTextBox.LostFocus += this.PART_EditableTextBox_LostFocus;\n\n            // Init Popup\n            this.PART_Popup = this.GetTemplateChild(nameof(this.PART_Popup)) as Popup ?? throw new MissingRequiredTemplatePartException(this, nameof(this.PART_Popup));\n            this.PART_PopupListBox = this.GetTemplateChild(nameof(this.PART_PopupListBox)) as ListBox ?? throw new MissingRequiredTemplatePartException(this, nameof(this.PART_PopupListBox));\n\n            if (this.PART_PopupListBox is not null)\n            {","sourceCodeStart":1172,"sourceCodeEnd":1208,"githubUrl":"https://github.com/MahApps/MahApps.Metro/blob/72099e310bac2d12ac98fd7560b69679252519f5/src/MahApps.Metro/Controls/MultiSelectionComboBox/MultiSelectionComboBox.cs#L1172-L1208","documentation":"Thrown by MultiSelectionComboBox.OnApplyTemplate when GetTemplateChild('PART_SelectedItemsPresenter') does not return a ListBox. MissingRequiredTemplatePartException (a MahAppsException subtype) indicates the ControlTemplate is missing a required named element. This means the control's default style is not applied or a custom template omits the part.","triggerScenarios":"Applying a custom ControlTemplate to MultiSelectionComboBox that lacks the 'PART_SelectedItemsPresenter' ListBox element. Also when the default Generic.xaml style is not merged (missing MahApps resource dictionaries) or when Themes/Generic.xaml is stripped during build.","commonSituations":"Developer creates a custom Style/ControlTemplate for MultiSelectionComboBox without including all required template parts. MahApps resource dictionaries not properly merged in App.xaml. Control used without its default theme after a NuGet package mismatch.","solutions":["Ensure MahApps.Metro resource dictionaries (MahApps.Metro.Styles.Theme) are merged in App.xaml so the default control template is available.","If defining a custom ControlTemplate, include a ListBox named 'PART_SelectedItemsPresenter'.","Check that the correct MahApps version's themes are referenced and no resource override hides the default style."],"exampleFix":"<!-- before: custom template missing parts -->\n<ControlTemplate TargetType=\"controls:MultiSelectionComboBox\">\n    <TextBox x:Name=\"PART_EditableTextBox\"/>\n</ControlTemplate>\n\n<!-- after -->\n<ControlTemplate TargetType=\"controls:MultiSelectionComboBox\">\n    <Grid>\n        <ListBox x:Name=\"PART_SelectedItemsPresenter\"/>\n        <TextBox x:Name=\"PART_EditableTextBox\"/>\n        <Popup x:Name=\"PART_Popup\">\n            <ListBox x:Name=\"PART_PopupListBox\"/>\n        </Popup>\n    </Grid>\n</ControlTemplate>","handlingStrategy":"validation","validationCode":"// Verify default style is applied before the control is shown\nif (combo.Template == null)\n{\n    // ensure MahApps resources are merged in App.xaml\n    throw new InvalidOperationException(\"MahApps theme resources not loaded\");\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    combo.ApplyTemplate();\n}\ncatch (MahAppsException ex) when (ex.Message.Contains(\"PART_SelectedItemsPresenter\"))\n{\n    // log and fall back to default template\n}","preventionTips":["Merge MahApps.Metro theme dictionaries in App.xaml.","When authoring custom templates, include all required PART_ elements.","Verify the default style key resolves correctly at design time."],"tags":["wpf","mahapps","template","control-template","combobox","resource-dictionary"],"backgroundTag":null,"analyzedSha":"72099e310bac2d12ac98fd7560b69679252519f5","analyzedAt":"2026-08-13T20:19:34.419Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}