{"record":{"id":"c4b12ef8814e7f60","repo":"stride3d/stride","slug":"the-given-element-is-not-a-child-of-this-panel","errorCode":null,"errorMessage":"The given element is not a child of this panel.","messagePattern":"The given element is not a child of this panel\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/editor/Stride.Assets.Presentation/AssetEditors/UIEditor/ViewModels/PanelViewModel.cs","lineNumber":189,"sourceCode":"\n                        default:\n                            throw new ArgumentException($\"{mode} is not a supported mode.\", nameof(mode));\n                    }\n\n                    var currentValue = GetDependencyPropertyValue(child, propertyKey);\n                    var newValue = Math.Max(0, currentValue + offset);\n                    SetDependencyPropertyValue(child, propertyKey, newValue);\n                    Editor.UndoRedoService.SetName(transaction, $\"Move {UIEditorBaseViewModel.GetDisplayName(child)}\");\n                    return;\n                }\n\n                var stackPanel = AssetSidePanel as StackPanel;\n                if (stackPanel != null)\n                {\n                    var collection = AssetSidePanel.Children;\n                    var index = collection.IndexOf(child);\n                    if (index == -1)\n                        throw new InvalidOperationException(\"The given element is not a child of this panel.\");\n\n                    int newIndex;\n                    switch (mode)\n                    {\n                        case PanelCommandMode.MoveDown:\n                            newIndex = index + 1;\n                            if (newIndex >= collection.Count)\n                                return;\n                            break;\n\n                        case PanelCommandMode.MoveUp:\n                            newIndex = index - 1;\n                            if (newIndex < 0)\n                                return;\n                            break;\n\n                        default:\n                            throw new ArgumentException($\"{mode} is not a supported mode.\", nameof(mode));","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/editor/Stride.Assets.Presentation/AssetEditors/UIEditor/ViewModels/PanelViewModel.cs#L171-L207","documentation":"PanelViewModel.ChangeChildElementLayoutProperties reorders a child inside its parent panel and throws this InvalidOperationException when collection.IndexOf(child) returns -1, i.e. the given element is not among the panel's Children. Reordering (MoveUp/MoveDown) is impossible without a valid current index.","triggerScenarios":"Calling ChangeChildElementLayoutProperties with a child belonging to a different panel, an element already removed, or a root-level element with no panel parent; move commands dispatched against the wrong/previous panel view model.","commonSituations":"Move up/down commands routed to a stale selection after the element was reparented, batch layout scripts assuming the child is still in the same panel, undo/redo leaving stale parent references.","solutions":["Verify the child is in AssetSidePanel.Children before invoking the layout command.","Resolve the child's actual parent panel at dispatch time instead of caching it.","Disable or skip move commands for root-level elements without a panel parent.","Refresh selection/parent references after undo/redo or reparenting."],"exampleFix":"// before\npanelViewModel.ChangeChildElementLayoutProperties(child, PanelCommandMode.MoveUp);\n// after\nif (panelViewModel.AssetSidePanel.Children.Contains(child.GetUIElement()))\n    panelViewModel.ChangeChildElementLayoutProperties(child, PanelCommandMode.MoveUp);\n","handlingStrategy":"validation","validationCode":"if (!panelViewModel.AssetSidePanel.Children.Contains(child.GetUIElement())) return; // not a child of this panel","typeGuard":"bool IsChildOfPanel(PanelViewModel panel, UIElementViewModel child) => panel.AssetSidePanel.Children.Contains(child.GetUIElement());","tryCatchPattern":"try { panel.ChangeChildElementLayoutProperties(child, mode); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"not a child of this panel\")) {\n    // re-resolve the child's actual parent panel and retry there\n}","preventionTips":["Dispatch move commands to the child's actual parent panel.","Disable move commands for root-level elements.","Refresh selection and parent references after reparenting or undo/redo.","Validate containment in the command layer before invoking."],"tags":["csharp","stride","ui-editor","entity-not-found"],"backgroundTag":"entity-not-found","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"}