{"record":{"id":"4677d5727803efd6","repo":"stride3d/stride","slug":"notsupportedexception-uibaseviewmodel","errorCode":null,"errorMessage":"NotSupportedException","messagePattern":"NotSupportedException","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"sources/editor/Stride.Assets.Presentation/ViewModel/UIBaseViewModel.cs","lineNumber":77,"sourceCode":"        /// <returns>The index in which to insert a child.</returns>\n        private int ResolveInsertionIndex(UIElement parent, int index)\n        {\n            if (parent == null)\n            {\n                return index >= 0 ? index : Asset.Hierarchy.RootParts.Count;\n            }\n\n            var control = parent as ContentControl;\n            if (control != null)\n            {\n                return index >= 0 ? index : 0;\n            }\n            var panel = parent as Panel;\n            if (panel != null)\n            {\n                return index >= 0 ? index : panel.Children.Count;\n            }\n            throw new NotSupportedException();\n        }\n    }\n}\n","sourceCodeStart":59,"sourceCodeEnd":81,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/editor/Stride.Assets.Presentation/ViewModel/UIBaseViewModel.cs#L59-L81","documentation":"UIBaseViewModel.ResolveInsertionIndex computes where to insert a UI element. If the visual parent is neither an IContentControl-like host nor a Panel (e.g. it is a ContentPresenter, Border, or other non-Panel container that exposes no children collection), no index can be resolved and it throws NotSupportedException. This is a deliberate fail-fast for unsupported visual-tree parents.","triggerScenarios":"Calling InsertUIElement (or InsertUIElementBefore/After) with a parent element whose XAML visual parent is not a Panel (not Grid/StackPanel/Canvas/etc.) and not a supported content control, or while the element is not yet attached to the visual tree so parent resolution lands on an unsupported type.","commonSituations":"Inserting a control inside a Border or ContentControl wrapper; inserting while the target container is still in a template (ContentPresenter); calling before the view is loaded so parent is a transitional visual type; custom panels that don't derive from Panel.","solutions":["Wrap the insertion target in a Panel-derived container (Grid/StackPanel) so the parent resolves as Panel.","Insert the element before it is wrapped, or target the actual Panel inside the template via FindAncestor/FindName.","Ensure the element is added to the visual tree (loaded) before calling InsertUIElement so parent is final.","If you own a custom container, derive it from Panel to gain Children-based insertion support."],"exampleFix":"// before\nviewModel.InsertUIElement(myControl, borderHost, index); // Border is not a Panel\n// after\nvar grid = new Grid();\ngrid.Children.Add(myControl);\nborderHost.Child = grid;\nviewModel.InsertUIElement(myControl, grid, index);","handlingStrategy":"validation","validationCode":"if (!(parent is Panel) && !(parent is IContentControl))\n    throw new InvalidOperationException($\"Parent {parent.GetType().Name} is not a supported insertion container\");\nviewModel.InsertUIElement(element, parent, index);","typeGuard":"bool IsInsertableContainer(object o) => o is Panel || o is IContentControl;","tryCatchPattern":null,"preventionTips":["Author XAML templates so dynamic elements live under Panel-derived containers.","Perform insertions after the view Loaded event so the visual tree is final.","Avoid inserting directly into Border/ContentPresenter wrappers."],"tags":["wpf","visual-tree","unsupported-operation","ui-composition"],"backgroundTag":"unsupported-operation","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"}