{"record":{"id":"05222e8092c90e5d","repo":"stride3d/stride","slug":"nameof-contentcontrol-name-control-name-already-has-a","errorCode":null,"errorMessage":"{nameof(ContentControl)} (Name={control.Name}) already has a content.","messagePattern":"(.+?) \\(Name=(.+?)\\) already has a content\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Assets/Quantum/UIAssetPropertyGraph.cs","lineNumber":63,"sourceCode":"                if (memberContent.Name == nameof(ContentControl.Content) && typeof(ContentControl).IsAssignableFrom(memberContent.Parent.Type))\n                    return true;\n            }\n            if ((node as IObjectNode)?.Type == typeof(UIElementCollection))\n            {\n                return true;\n            }\n            return false;\n        }\n\n        /// <inheritdoc/>\n        protected override void AddChildPartToParentPart(UIElement parentPart, UIElement childPart, int index)\n        {\n            var control = parentPart as ContentControl;\n            if (control != null)\n            {\n                var node = Container.NodeContainer.GetOrCreateNode(control)[nameof(ContentControl.Content)];\n                if (node.Retrieve() != null)\n                    throw new InvalidOperationException($\"{nameof(ContentControl)} (Name={control.Name}) already has a content.\");\n\n                node.Update(childPart);\n                return;\n            }\n            var panel = parentPart as Panel;\n            if (panel != null)\n            {\n                var node = Container.NodeContainer.GetOrCreateNode(panel)[nameof(Panel.Children)].Target;\n                if (index < 0)\n                    node.Add(childPart);\n                else\n                    node.Add(childPart, new NodeIndex(index));\n                return;\n            }\n            throw new NotSupportedException();\n        }\n\n        /// <inheritdoc/>","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Assets/Quantum/UIAssetPropertyGraph.cs#L45-L81","documentation":"In UIAssetPropertyGraph, when a new UI child is attached to a ContentControl parent, the Quantum node backing ContentControl.Content must be null. If the control already has content, AddChildPartToParentPart throws InvalidOperationException, because a ContentControl can hold exactly one child.","triggerScenarios":"Adding a second child to a ContentControl in the UI editor / asset graph, or programmatically calling AddChildPartToParentPart on a ContentControl whose Content node already stores a part.","commonSituations":"Dragging a new element onto a Button/ContentControl that already contains one, restoring a UI asset where a stale Quantum node still references a removed control, or duplicated undo/redo operations re-adding the same child.","solutions":["Remove the existing child of the ContentControl before adding the new one","Use a Panel (StackPanel/Grid) instead of ContentControl when multiple children are needed","If caused by a stale node, reopen/reload the UI asset to resynchronize the Quantum container","Delete and recreate the corrupted ContentControl in the editor"],"exampleFix":"// before\ncontentControl.Content = imageA;\ngraph.AddChildPartToParentPart(contentControl, imageB); // throws\n// after\ncontentControl.Content = null;\ngraph.AddChildPartToParentPart(contentControl, imageB);","handlingStrategy":"type-guard","validationCode":"var node = Container.NodeContainer.GetOrCreateNode(control)[nameof(ContentControl.Content)];\nif (node.Retrieve() != null) { /* remove existing child or choose a Panel parent first */ }","typeGuard":"bool canAddChild(UIElement parent) =>\n    parent is Panel || (parent is ContentControl c &&\n        Container.NodeContainer.GetOrCreateNode(c)[nameof(ContentControl.Content)].Retrieve() == null);","tryCatchPattern":"try\n{\n    graph.AddChildPartToParentPart(parent, child);\n}\ncatch (InvalidOperationException)\n{\n    // ContentControl already occupied: clear content or use a Panel\n}","preventionTips":["Remember ContentControl holds exactly one child","Use Panels for multiple children","Reload the asset after undo/redo oddities before editing again","Avoid scripted bulk edits that may re-add existing children"],"tags":["ui","quantum","invalid-state"],"backgroundTag":"invalid-state-transition","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}