MahApps/MahApps.Metro · error · MissingRequiredTemplatePartException
Template part "{templatePart}" in template for "{target.GetT
Error message
Template part "{templatePart}" in template for "{target.GetType().FullName}" is missing. What it means
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.
Source
Thrown at src/MahApps.Metro/Controls/MultiSelectionComboBox/MultiSelectionComboBox.cs:1190
if (sender is MultiSelectionComboBox)
{
e.CanExecute = e.Parameter != null;
}
}
#endregion
#region Overrides
public override void OnApplyTemplate()
{
this.StopListeningForSelectionChanges();
base.OnApplyTemplate();
// Init SelectedItemsPresenter
var selectedItemsPresenterName = nameof(this.PART_SelectedItemsPresenter);
this.PART_SelectedItemsPresenter = this.GetTemplateChild(selectedItemsPresenterName) as ListBox ?? throw new MissingRequiredTemplatePartException(this, selectedItemsPresenterName);
this.PART_SelectedItemsPresenter.MouseLeftButtonUp -= this.PART_SelectedItemsPresenter_MouseLeftButtonUp;
this.PART_SelectedItemsPresenter.MouseLeftButtonUp += this.PART_SelectedItemsPresenter_MouseLeftButtonUp;
this.PART_SelectedItemsPresenter.SelectionChanged -= this.PART_SelectedItemsPresenter_SelectionChanged;
this.PART_SelectedItemsPresenter.SelectionChanged += this.PART_SelectedItemsPresenter_SelectionChanged;
// Init EditableTextBox
this.PART_EditableTextBox = this.GetTemplateChild(nameof(this.PART_EditableTextBox)) as TextBox ?? throw new MissingRequiredTemplatePartException(this, nameof(this.PART_EditableTextBox));
this.PART_EditableTextBox.LostFocus -= this.PART_EditableTextBox_LostFocus;
this.PART_EditableTextBox.LostFocus += this.PART_EditableTextBox_LostFocus;
// Init Popup
this.PART_Popup = this.GetTemplateChild(nameof(this.PART_Popup)) as Popup ?? throw new MissingRequiredTemplatePartException(this, nameof(this.PART_Popup));
this.PART_PopupListBox = this.GetTemplateChild(nameof(this.PART_PopupListBox)) as ListBox ?? throw new MissingRequiredTemplatePartException(this, nameof(this.PART_PopupListBox));
if (this.PART_PopupListBox is not null)
{View on GitHub (pinned to 72099e310b)
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.
Example fix
<!-- before: custom template missing parts -->
<ControlTemplate TargetType="controls:MultiSelectionComboBox">
<TextBox x:Name="PART_EditableTextBox"/>
</ControlTemplate>
<!-- after -->
<ControlTemplate TargetType="controls:MultiSelectionComboBox">
<Grid>
<ListBox x:Name="PART_SelectedItemsPresenter"/>
<TextBox x:Name="PART_EditableTextBox"/>
<Popup x:Name="PART_Popup">
<ListBox x:Name="PART_PopupListBox"/>
</Popup>
</Grid>
</ControlTemplate> Defensive patterns
Strategy: validation
Validate before calling
// Verify default style is applied before the control is shown
if (combo.Template == null)
{
// ensure MahApps resources are merged in App.xaml
throw new InvalidOperationException("MahApps theme resources not loaded");
} Try / catch
try
{
combo.ApplyTemplate();
}
catch (MahAppsException ex) when (ex.Message.Contains("PART_SelectedItemsPresenter"))
{
// log and fall back to default template
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- You have missed to specify PART_NumericUp, PART_NumericDown
- Template part "{templatePart}" in template for "{target.GetT
- OptionsListView is not defined yet. Please use OptionsItemsS
- ButtonsListView is not defined yet. Please use ItemsSource i
- OverlayBox can not be founded in this MetroWindow's template
AI-assisted analysis of MahApps/MahApps.Metro@72099e310b (2026-08-13).
Data as JSON: /api/errors/622b12e70b616103.
Report an issue: GitHub.