{"record":{"id":"5754eb4e36c50c12","repo":"MahApps/MahApps.Metro","slug":"unable-to-find-the-dialog-closing-storyboard-did","errorCode":null,"errorMessage":"Unable to find the dialog closing storyboard. Did you forget to add BaseMetroDialog.xaml to your merged dictionaries?","messagePattern":"Unable to find the dialog closing storyboard\\. Did you forget to add BaseMetroDialog\\.xaml to your merged dictionaries\\?","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/MahApps.Metro/Controls/Dialogs/BaseMetroDialog.cs","lineNumber":514,"sourceCode":"        {\n            var tcs = new TaskCompletionSource<object>();\n\n            this.Unloaded += (_, _) => { tcs.TrySetResult(null!); };\n\n            return tcs.Task;\n        }\n\n        private EventHandler? closingStoryboardOnCompleted;\n\n        public Task WaitForCloseAsync()\n        {\n            var tcs = new TaskCompletionSource<object>();\n\n            if (this.DialogSettings.AnimateHide)\n            {\n                if (this.TryFindResource(\"MahApps.Storyboard.Dialogs.Close\") is not Storyboard closingStoryboard)\n                {\n                    throw new InvalidOperationException(\"Unable to find the dialog closing storyboard. Did you forget to add BaseMetroDialog.xaml to your merged dictionaries?\");\n                }\n\n                closingStoryboard = closingStoryboard.Clone();\n\n                this.closingStoryboardOnCompleted = (_, _) =>\n                    {\n                        closingStoryboard.Completed -= this.closingStoryboardOnCompleted;\n\n                        tcs.TrySetResult(null!);\n                    };\n\n                closingStoryboard.Completed += this.closingStoryboardOnCompleted;\n\n                closingStoryboard.Begin(this);\n            }\n            else\n            {\n                this.SetCurrentValue(OpacityProperty, 0.0);","sourceCodeStart":496,"sourceCodeEnd":532,"githubUrl":"https://github.com/MahApps/MahApps.Metro/blob/72099e310bac2d12ac98fd7560b69679252519f5/src/MahApps.Metro/Controls/Dialogs/BaseMetroDialog.cs#L496-L532","documentation":"WaitForCloseAsync animates a dialog's hide using the 'MahApps.Storyboard.Dialogs.Close' resource. When DialogSettings.AnimateHide is true but TryFindResource returns nothing (the resource key is absent from the dialog's resources), it throws InvalidOperationException pointing at the missing BaseMetroDialog.xaml. The resource ships inside the MahApps.Metro dialog templates, so its absence means the templates were not merged into the application's resource dictionaries.","triggerScenarios":"A BaseMetroDialog (or subclass) is shown with AnimateHide == true, and when it closes WaitForCloseAsync cannot find the 'MahApps.Storyboard.Dialogs.Close' Storyboard resource — typically because the MahApps.Metro dialog resource dictionaries were not merged into App.xaml or the dialog's own resources.","commonSituations":"App uses MahApps dialogs but forgot to merge MahApps.Metro.Resources.Dialogs (or the BaseMetroDialog template) into MergedDictionaries. A custom dialog template removed the closing storyboard. Resource cleanup/replacement dropped the key. An older MahApps version whose key name differs.","solutions":["Merge the MahApps.Metro dialog resource dictionaries into App.xaml (e.g. <ResourceDictionary Source=\"pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml\"/>) so the storyboard key is available globally.","If you use a custom dialog template, ensure it (or its merged dictionaries) defines the 'MahApps.Storyboard.Dialogs.Close' Storyboard.","Alternatively set DialogSettings.AnimateHide = false to skip the animation path that needs the storyboard.","Verify the correct MahApps.Metro version is referenced; the resource key exists in the shipped BaseMetroDialog.xaml."],"exampleFix":"<!-- before: dialogs work but AnimateHide throws on close -->\n<Application.Resources/>\n<!-- after: merge the MahApps control/dialog resources -->\n<Application.Resources>\n  <ResourceDictionary>\n    <ResourceDictionary.MergedDictionaries>\n      <ResourceDictionary Source=\"pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml\"/>\n    </ResourceDictionary.MergedDictionaries>\n  </ResourceDictionary>\n</Application.Resources>","handlingStrategy":"validation","validationCode":"// Ensure the closing storyboard resource is resolvable before enabling AnimateHide\nbool hasCloseStoryboard = dialog.TryFindResource(\"MahApps.Storyboard.Dialogs.Close\") is Storyboard;\ndialog.DialogSettings.AnimateHide = hasCloseStoryboard;\ndialog.DialogSettings.AnimateShow = hasCloseStoryboard;","typeGuard":null,"tryCatchPattern":"try {\n    await dialogCoordinator.HideMetroDialogAsync(context, dialog);\n} catch (InvalidOperationException ex) when (ex.Message.Contains(\"closing storyboard\")) {\n    // fall back to non-animated close\n    dialog.DialogSettings.AnimateHide = false;\n    await dialogCoordinator.HideMetroDialogAsync(context, dialog);\n}","preventionTips":["Merge the MahApps.Metro dialog/control resource dictionaries into App.xaml so the storyboard key is global.","If you ship a custom dialog template, keep the 'MahApps.Storyboard.Dialogs.Close' Storyboard resource in it.","Disable AnimateHide/AnimateShow if your resource set lacks the storyboard rather than letting it throw.","Pin the MahApps.Metro version whose resource keys you author templates against."],"tags":["wpf","dialog","animation","resources","xaml","runtime"],"backgroundTag":null,"analyzedSha":"72099e310bac2d12ac98fd7560b69679252519f5","analyzedAt":"2026-08-13T20:19:34.419Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}