MahApps/MahApps.Metro · error · InvalidOperationException
Inactive dialog container could not be found.
Error message
Inactive dialog container could not be found.
What it means
ShowMetroDialogAsync also requires the inactive container (PART_MetroInactiveDialogsContainer), used for modal/behind dialogs. If window.metroInactiveDialogContainer is null it throws InvalidOperationException naming the inactive container. This is the second guard in the same method, fired only when the active container was already present.
Source
Thrown at src/MahApps.Metro/Controls/Dialogs/DialogManager.cs:296
/// <para>You have to close the resulting dialog yourself with <see cref="HideMetroDialogAsync"/>.</para>
/// </summary>
/// <param name="window">The owning window of the dialog.</param>
/// <param name="dialog">The dialog instance itself.</param>
/// <param name="settings">An optional pre-defined settings instance.</param>
/// <returns>A task representing the operation.</returns>
/// <exception cref="InvalidOperationException">The <paramref name="dialog"/> is already visible in the window.</exception>
public static async Task ShowMetroDialogAsync(this MetroWindow window, BaseMetroDialog dialog, MetroDialogSettings? settings = null)
{
window.Dispatcher.VerifyAccess();
if (window.metroActiveDialogContainer is null)
{
throw new InvalidOperationException("Active dialog container could not be found.");
}
if (window.metroInactiveDialogContainer is null)
{
throw new InvalidOperationException("Inactive dialog container could not be found.");
}
if (window.metroActiveDialogContainer.Children.Contains(dialog) || window.metroInactiveDialogContainer.Children.Contains(dialog))
{
throw new InvalidOperationException("The provided dialog is already visible in the specified window.");
}
settings ??= dialog.DialogSettings;
await HandleOverlayOnShowAsync(settings, window);
SetDialogFontSizes(settings, dialog);
dialog.SizeChangedHandler = SetupAndAddDialog(window, dialog);
await dialog.WaitForLoadAsync();
DialogOpened?.Invoke(window, new DialogStateChangedEventArgs(dialog));View on GitHub (pinned to 72099e310b)
Solutions
- Add the PART_MetroInactiveDialogsContainer Grid (named exactly) to your custom MetroWindow ControlTemplate alongside PART_MetroActiveDialogContainer.
Example fix
<!-- before: only the active container is present -->
<ControlTemplate TargetType="{x:Type controls:MetroWindow}">
<Grid>
<ContentPresenter/>
<Grid x:Name="PART_MetroActiveDialogContainer"/>
<!-- inactive container missing -->
</Grid>
</ControlTemplate>
<!-- after -->
<ControlTemplate TargetType="{x:Type controls:MetroWindow}">
<Grid>
<ContentPresenter/>
<Grid x:Name="PART_MetroActiveDialogContainer"/>
<Grid x:Name="PART_MetroInactiveDialogsContainer"/>
</Grid>
</ControlTemplate> Defensive patterns
Strategy: validation
Validate before calling
// Validate both containers before showing
if (window.metroActiveDialogContainer is null || window.metroInactiveDialogContainer is null) {
throw new InvalidOperationException(
"MetroWindow template must define PART_MetroActiveDialogContainer and PART_MetroInactiveDialogsContainer.");
} Try / catch
try {
await window.ShowMetroDialogAsync(dialog);
} catch (InvalidOperationException ex) when (ex.Message.Contains("Inactive dialog container could not be found")) {
// add PART_MetroInactiveDialogsContainer to the template; do not retry blindly
} Prevention
- Always include both dialog container parts in custom MetroWindow templates.
- Add an OnApplyTemplate assertion verifying both PART_MetroActiveDialogContainer and PART_MetroInactiveDialogsContainer resolved.
- Document required template parts in any published MetroWindow style.
- Validate templates against the shipped default before replacing them.
When it happens
Trigger: Showing a dialog on a MetroWindow whose ControlTemplate supplied PART_MetroActiveDialogContainer but not PART_MetroInactiveDialogsContainer, so window.metroInactiveDialogContainer stays null and ShowMetroDialogAsync throws on the second guard.
Common situations: A custom MetroWindow ControlTemplate included only the active dialog container and forgot the inactive one. A template ported from an older version that did not have the inactive container. Partial template editing that renamed/removed the part.
Related errors
- Active dialog container could not be found.
- The context `{context}` is not inside a MetroWindow.
- The inverse dialog theme only works if the window theme abid
- Unable to find the dialog closing storyboard. Did you forget
- The context `{context}` is not registered. Consider using th
AI-assisted analysis of MahApps/MahApps.Metro@72099e310b (2026-08-13).
Data as JSON: /api/errors/ee61172fdeb9bc2c.
Report an issue: GitHub.