{"record":{"id":"bed83d5570e2bf60","repo":"MahApps/MahApps.Metro","slug":"the-context-context-is-not-registered-conside","errorCode":null,"errorMessage":"The context `{context}` is not registered. Consider using the DialogParticipation.Register property in XAML to bind in the DataContext.","messagePattern":"The context `(.+?)` is not registered\\. Consider using the DialogParticipation\\.Register property in XAML to bind in the DataContext\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/MahApps.Metro/Controls/Dialogs/DialogCoordinator.cs","lineNumber":88,"sourceCode":"        }\n\n        public Task<TDialog?> GetCurrentDialogAsync<TDialog>(object context)\n            where TDialog : BaseMetroDialog\n        {\n            var metroWindow = GetMetroWindow(context);\n            return metroWindow.Invoke(() => metroWindow.GetCurrentDialogAsync<TDialog>());\n        }\n\n        private static MetroWindow GetMetroWindow(object context)\n        {\n            if (context is null)\n            {\n                throw new ArgumentNullException(nameof(context));\n            }\n\n            if (DialogParticipation.IsRegistered(context) == false)\n            {\n                throw new InvalidOperationException($\"The context `{context}` is not registered. Consider using the DialogParticipation.Register property in XAML to bind in the DataContext.\");\n            }\n\n            var association = DialogParticipation.GetAssociation(context);\n            var metroWindow = association.Invoke(() => Window.GetWindow(association) as MetroWindow);\n            if (metroWindow is null)\n            {\n                throw new InvalidOperationException($\"The context `{context}` is not inside a MetroWindow.\");\n            }\n\n            return metroWindow;\n        }\n    }\n}","sourceCodeStart":70,"sourceCodeEnd":101,"githubUrl":"https://github.com/MahApps/MahApps.Metro/blob/72099e310bac2d12ac98fd7560b69679252519f5/src/MahApps.Metro/Controls/Dialogs/DialogCoordinator.cs#L70-L101","documentation":"DialogCoordinator.GetMetroWindow(context) requires the context object to be registered first via the DialogParticipation.Register attached property. It calls DialogParticipation.IsRegistered(context); if false it throws InvalidOperationException telling you to set DialogParticipation.Register in XAML bound to the DataContext. This guards every DialogCoordinator call that needs the hosting window.","triggerScenarios":"Calling any DialogCoordinator method (ShowMessageAsync, ShowModalAsync, ShowMetroDialogAsync, GetCurrentDialogAsync, etc.) with a context object that was never registered via DialogParticipation.SetRegister / the Register attached property on a view. The internal ContextRegistrationIndex does not contain the object.","commonSituations":"A ViewModel calls DialogCoordinator instance methods but the corresponding View never sets <i:Interaction.Behaviors> DialogParticipation.Register=\"{Binding}\" (or attaches it to the wrong element). The context passed is a different object than the one registered (new instance, boxed value equality). View unloaded and unregistered the context before the call.","solutions":["Attach DialogParticipation.Register to the root element of the View whose DataContext is the VM, bound to the same context you pass to DialogCoordinator (e.g. DialogParticipation.Register=\"{Binding}\" on the MetroWindow or UserControl).","Ensure the SAME object reference is used for registration and for the DialogCoordinator call (do not pass a freshly constructed copy).","Register before showing the dialog (registration happens in XAML when the view loads); avoid calling the coordinator before the view is loaded.","Set MetroDialogSettings.OwnerCanCloseWithDialog appropriately and confirm the owning view is alive at call time."],"exampleFix":"<!-- before: VM calls ShowMessageAsync(this) but nothing registers it -->\n<MetroWindow .../>\n// VM:\nawait _dialogCoord.ShowMessageAsync(this, \"Hi\");\n<!-- after: register the DataContext on the view -->\n<MetroWindow ... DialogParticipation.Register=\"{Binding RelativeSource={RelativeSource Self}, Path=DataContext}\">","handlingStrategy":"validation","validationCode":"// Before calling the coordinator, verify the context is registered\nif (!DialogParticipation.IsRegistered(context)) {\n    throw new InvalidOperationException(\n        $\"Register '{context}' via DialogParticipation.Register on the view before using DialogCoordinator.\");\n}\nawait dialogCoordinator.ShowMessageAsync(context, \"Hello\");","typeGuard":null,"tryCatchPattern":"try {\n    await dialogCoordinator.ShowMessageAsync(context, \"Hello\");\n} catch (InvalidOperationException ex) when (ex.Message.Contains(\"not registered\")) {\n    // register and retry, or surface a setup error to the developer\n}","preventionTips":["Set DialogParticipation.Register=\"{Binding}\" on the MetroWindow (or the host element) whose DataContext is the VM.","Use the same object reference for registration and for DialogCoordinator calls.","Call DialogCoordinator methods only after the view has Loaded (registration happens on load).","Add a startup/design-time check that asserts the VM is registered."],"tags":["wpf","dialog","caliburn-style","mvvm","registration","runtime"],"backgroundTag":null,"analyzedSha":"72099e310bac2d12ac98fd7560b69679252519f5","analyzedAt":"2026-08-13T20:19:34.419Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}