{"record":{"id":"1c8ffd3ca563a541","repo":"stride3d/stride","slug":"this-operation-can-only-be-executed-on-a-selection-of","errorCode":null,"errorMessage":"This operation can only be executed on a selection of sibling elements.","messagePattern":"This operation can only be executed on a selection of sibling elements\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/editor/Stride.Assets.Presentation/AssetEditors/UIEditor/ViewModels/UIEditorBaseViewModel.cs","lineNumber":603,"sourceCode":"            return Controller.AdornerService.GetElementIdsAtPosition(ref worldPosition).Select(id => FindPartViewModel(new AbsoluteId(Asset.Id, id))).OfType<UIElementViewModel>();\n        }\n\n        private void GroupInto(IUIElementFactory factory)\n        {\n            var targetPanelType = (factory as UIElementFromSystemLibrary)?.Type;\n            if (targetPanelType == null)\n                throw new NotSupportedException(\"Grouping elements into a user library type isn't supported.\");\n            if (!typeof(Panel).IsAssignableFrom(targetPanelType))\n                throw new ArgumentException(@\"The target type isn't a panel\", nameof(targetPanelType));\n\n            if (SelectedContent.Count == 0)\n                return;\n\n            // Ensure that the selected elements are sibling.\n            var allParents = SelectedItems.Select(x => x.Parent).OfType<UIHierarchyItemViewModel>().ToList();\n            var parent = allParents[0];\n            if (allParents.Any(x => x != parent))\n                throw new InvalidOperationException(\"This operation can only be executed on a selection of sibling elements.\");\n\n            using (var transaction = UndoRedoService.CreateTransaction())\n            {\n                var children = SelectedItems.ToList();\n                // Create the new panel into which we'll insert the selection\n                var newPanel = (Panel)Activator.CreateInstance(targetPanelType);\n                var newPanelDesign = new UIElementDesign(newPanel);\n                // Create a hierarchy containing all children and the panel\n                var hierarchy = UIAssetPropertyGraph.CloneSubHierarchies(Asset.Session.AssetNodeContainer, Asset.Asset, children.Select(c => c.Id.ObjectId), SubHierarchyCloneFlags.None, out _);\n                hierarchy.RootParts.Add(newPanel);\n                hierarchy.Parts.Add(newPanelDesign);\n                // Remove all children from their partDesign panel.\n                foreach (var child in children)\n                {\n                    child.Asset.AssetHierarchyPropertyGraph.RemovePartFromAsset(child.UIElementDesign);\n                }\n                // Add the new panel in place of the selected content.\n                parent.Asset.InsertUIElement(hierarchy.Parts, newPanelDesign, (parent as UIElementViewModel)?.AssetSideUIElement);","sourceCodeStart":585,"sourceCodeEnd":621,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/editor/Stride.Assets.Presentation/AssetEditors/UIEditor/ViewModels/UIEditorBaseViewModel.cs#L585-L621","documentation":"Thrown by UIEditorBaseViewModel when a group operation (e.g. wrapping the selection into a new Panel) is executed on a selection whose elements do not all share the same parent. The editor groups SelectedItems by comparing each item's Parent; if more than one distinct parent UIHierarchyItemViewModel exists, the operation is invalid because only siblings can be re-parented into a single new panel together.","triggerScenarios":"Calling the group-into-panel command in the UI editor with SelectedItems containing elements from different containers/panels, e.g. multi-selecting one element inside PanelA and another inside PanelB then invoking the grouping action.","commonSituations":"Multi-selecting UI elements across different branches of the visual tree with ctrl+click and then using a 'group' or 'wrap in panel' command; scripted editor automation that fills SelectedItems without checking hierarchy.","solutions":["Select only elements that are direct children of the same parent before running the group command.","Group elements one branch at a time: group siblings within a panel first, then group the resulting panels.","If scripting, filter SelectedItems so that all items satisfy item.Parent == first.Parent before invoking the operation."],"exampleFix":"// before\nviewModel.SelectedItems = mixedSelection; // elements with different parents\nviewModel.GroupIntoPanel(typeof(Grid));\n// after\nvar parent = ((UIHierarchyItemViewModel)mixedSelection[0]).Parent;\nviewModel.SelectedItems = mixedSelection.Cast<UIHierarchyItemViewModel>().Where(x => x.Parent == parent).ToList();\nviewModel.GroupIntoPanel(typeof(Grid));","handlingStrategy":"validation","validationCode":"bool selectionIsSiblings = selectedItems.Cast<UIHierarchyItemViewModel>().Select(x => x.Parent).Distinct().Count() <= 1;","typeGuard":"static bool AreSiblings(IEnumerable<UIHierarchyItemViewModel> items) => items.Select(x => x.Parent).Distinct().Count() <= 1;","tryCatchPattern":"try { viewModel.GroupIntoPanel(typeof(Grid)); } catch (InvalidOperationException ex) { /* prompt: select only sibling elements */ }","preventionTips":["Only multi-select elements shown under the same parent node.","Add UI-level enablement: disable group commands unless selection is homogeneous in Parent.","In scripts, filter selection by shared Parent before invoking editor commands."],"tags":["wpf","ui-editor","invalid-selection","invalidoperationexception"],"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-16T04:17:20.429Z"}