{"record":{"id":"e7f289b1011e1bb2","repo":"MaterialDesignInXAML/MaterialDesignInXamlToolkit","slug":"content-cannot-be-passed-to-a-dialog-via-the-opend","errorCode":null,"errorMessage":"Content cannot be passed to a dialog via the OpenDialog if DialogContent already has a binding.","messagePattern":"Content cannot be passed to a dialog via the OpenDialog if DialogContent already has a binding\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/MaterialDesignThemes.Wpf/DialogHost.cs","lineNumber":797,"sourceCode":"    /// <summary>\n    /// Callback fired when the <see cref=\"DialogClosed\"/> event is fired, allowing the event to be processed from a binding/view model.\n    /// </summary>\n    public DialogClosedEventHandler? DialogClosedCallback\n    {\n        get => (DialogClosedEventHandler?)GetValue(DialogClosedCallbackProperty);\n        set => SetValue(DialogClosedCallbackProperty, value);\n    }\n\n    protected void OnDialogClosed(DialogClosedEventArgs eventArgs)\n        => RaiseEvent(eventArgs);\n\n    #endregion\n\n    internal void AssertTargetableContent()\n    {\n        var existingBinding = BindingOperations.GetBindingExpression(this, DialogContentProperty);\n        if (existingBinding != null)\n            throw new InvalidOperationException(\n                \"Content cannot be passed to a dialog via the OpenDialog if DialogContent already has a binding.\");\n    }\n\n    internal void InternalClose(object? parameter)\n    {\n        var currentSession = CurrentSession ?? throw new InvalidOperationException($\"{nameof(DialogHost)} does not have a current session\");\n\n        currentSession.CloseParameter = parameter;\n        currentSession.IsEnded = true;\n\n        //multiple ways of calling back that the dialog is closing:\n        // * routed event\n        // * the attached property (which should be applied to the button which opened the dialog\n        // * straight forward IsOpen dependency property \n        // * handler provided to the async show method\n        var dialogClosingEventArgs = new DialogClosingEventArgs(currentSession, DialogClosingEvent);\n        OnDialogClosing(dialogClosingEventArgs);\n        _attachedDialogClosingEventHandler?.Invoke(this, dialogClosingEventArgs);","sourceCodeStart":779,"sourceCodeEnd":815,"githubUrl":"https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit/blob/98edec3a0b96ef272c587b14bcd67ef5f928a7ed/src/MaterialDesignThemes.Wpf/DialogHost.cs#L779-L815","documentation":"AssertTargetableContent rejects passing content via the OpenDialog/Show APIs when DialogContentProperty already has a WPF Binding expression. The host cannot overwrite a bound DialogContent without breaking the binding, so ShowInternal calls AssertTargetableContent early (DialogHost.cs:265) and the check at :798 throws if a BindingExpression exists.","triggerScenarios":"XAML binds DialogContent (e.g. DialogContent=\"{Binding ...}\") and code then calls Show(content), ShowInternal(content, ...) or DialogSession.UpdateContent(content) with a non-null content object.","commonSituations":"Designer/data-template bound DialogContent while app code tries to inject a runtime control; migrating from IsOpen binding pattern to async Show pattern without removing the XAML binding; partial views where both a binding and imperative Show are wired.","solutions":["Remove the Binding on DialogContent in XAML and pass content via Show(content) / Show(content, identifier) instead.","If the binding is required, do not pass content to Show; rely on the bound view model and just toggle IsOpen or call Show(null).","Audit XAML for 'DialogContent=' bindings and reconcile with the chosen open-dialog pattern."],"exampleFix":"<!-- before -->\n<materialDesign:DialogHost DialogContent=\"{Binding MyContent}\" />\n\n<!-- after (use imperative Show) -->\n<materialDesign:DialogHost Identifier=\"RootDialog\" />\n// await DialogHost.Show(new MyView(), \"RootDialog\");","handlingStrategy":"validation","validationCode":"var binding = BindingOperations.GetBindingExpression(dialogHost, DialogHost.DialogContentProperty);\nif (binding is not null)\n    throw new InvalidOperationException(\"Remove the DialogContent binding before using Show(content).\");\n\nawait dialogHost.Show(content);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pick ONE dialog pattern: either bind DialogContent in XAML or pass content via Show—not both.","Audit XAML for 'DialogContent=' bindings before switching to imperative Show.","If a binding is needed, call Show(null) and toggle IsOpen instead of passing content."],"tags":["wpf","materialdesigninxaml","binding","xaml","dialog"],"backgroundTag":null,"analyzedSha":"98edec3a0b96ef272c587b14bcd67ef5f928a7ed","analyzedAt":"2026-08-13T14:31:19.111Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}