{"record":{"id":"ee61172fdeb9bc2c","repo":"MahApps/MahApps.Metro","slug":"inactive-dialog-container-could-not-be-found","errorCode":null,"errorMessage":"Inactive dialog container could not be found.","messagePattern":"Inactive dialog container could not be found\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/MahApps.Metro/Controls/Dialogs/DialogManager.cs","lineNumber":296,"sourceCode":"        /// <para>You have to close the resulting dialog yourself with <see cref=\"HideMetroDialogAsync\"/>.</para>\n        /// </summary>\n        /// <param name=\"window\">The owning window of the dialog.</param>\n        /// <param name=\"dialog\">The dialog instance itself.</param>\n        /// <param name=\"settings\">An optional pre-defined settings instance.</param>\n        /// <returns>A task representing the operation.</returns>\n        /// <exception cref=\"InvalidOperationException\">The <paramref name=\"dialog\"/> is already visible in the window.</exception>\n        public static async Task ShowMetroDialogAsync(this MetroWindow window, BaseMetroDialog dialog, MetroDialogSettings? settings = null)\n        {\n            window.Dispatcher.VerifyAccess();\n\n            if (window.metroActiveDialogContainer is null)\n            {\n                throw new InvalidOperationException(\"Active dialog container could not be found.\");\n            }\n\n            if (window.metroInactiveDialogContainer is null)\n            {\n                throw new InvalidOperationException(\"Inactive dialog container could not be found.\");\n            }\n\n            if (window.metroActiveDialogContainer.Children.Contains(dialog) || window.metroInactiveDialogContainer.Children.Contains(dialog))\n            {\n                throw new InvalidOperationException(\"The provided dialog is already visible in the specified window.\");\n            }\n\n            settings ??= dialog.DialogSettings;\n\n            await HandleOverlayOnShowAsync(settings, window);\n\n            SetDialogFontSizes(settings, dialog);\n\n            dialog.SizeChangedHandler = SetupAndAddDialog(window, dialog);\n\n            await dialog.WaitForLoadAsync();\n\n            DialogOpened?.Invoke(window, new DialogStateChangedEventArgs(dialog));","sourceCodeStart":278,"sourceCodeEnd":314,"githubUrl":"https://github.com/MahApps/MahApps.Metro/blob/72099e310bac2d12ac98fd7560b69679252519f5/src/MahApps.Metro/Controls/Dialogs/DialogManager.cs#L278-L314","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Add the PART_MetroInactiveDialogsContainer Grid (named exactly) to your custom MetroWindow ControlTemplate alongside PART_MetroActiveDialogContainer."],"exampleFix":"<!-- before: only the active container is present -->\n<ControlTemplate TargetType=\"{x:Type controls:MetroWindow}\">\n  <Grid>\n    <ContentPresenter/>\n    <Grid x:Name=\"PART_MetroActiveDialogContainer\"/>\n    <!-- inactive container missing -->\n  </Grid>\n</ControlTemplate>\n<!-- after -->\n<ControlTemplate TargetType=\"{x:Type controls:MetroWindow}\">\n  <Grid>\n    <ContentPresenter/>\n    <Grid x:Name=\"PART_MetroActiveDialogContainer\"/>\n    <Grid x:Name=\"PART_MetroInactiveDialogsContainer\"/>\n  </Grid>\n</ControlTemplate>","handlingStrategy":"validation","validationCode":"// Validate both containers before showing\nif (window.metroActiveDialogContainer is null || window.metroInactiveDialogContainer is null) {\n    throw new InvalidOperationException(\n        \"MetroWindow template must define PART_MetroActiveDialogContainer and PART_MetroInactiveDialogsContainer.\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    await window.ShowMetroDialogAsync(dialog);\n} catch (InvalidOperationException ex) when (ex.Message.Contains(\"Inactive dialog container could not be found\")) {\n    // add PART_MetroInactiveDialogsContainer to the template; do not retry blindly\n}","preventionTips":["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."],"tags":["wpf","dialog","metro-window","control-template","template-part","runtime"],"backgroundTag":null,"analyzedSha":"72099e310bac2d12ac98fd7560b69679252519f5","analyzedAt":"2026-08-13T20:19:34.419Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}