{"record":{"id":"61957adc969408ee","repo":"dotnet/maui","slug":"element-must-be-a-tabbedpage-61957a","errorCode":null,"errorMessage":"Element must be a TabbedPage","messagePattern":"Element must be a TabbedPage","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Compatibility/Core/src/Windows/TabbedPageRenderer.cs","lineNumber":156,"sourceCode":"\n\t\t\tControl.Measure(constraint);\n\t\t\tvar result = new Size(Math.Ceiling(Control.DesiredSize.Width), Math.Ceiling(Control.DesiredSize.Height));\n\n\t\t\tControl.Width = oldWidth;\n\t\t\tControl.Height = oldHeight;\n\n\t\t\treturn new SizeRequest(result);\n\t\t}\n\n\t\tUIElement IVisualElementRenderer.GetNativeElement()\n\t\t{\n\t\t\treturn Control;\n\t\t}\n\n\t\tpublic void SetElement(VisualElement element)\n\t\t{\n\t\t\tif (element != null && !(element is TabbedPage))\n\t\t\t\tthrow new ArgumentException(\"Element must be a TabbedPage\", \"element\");\n\n\t\t\tTabbedPage oldElement = Element;\n\t\t\tElement = (TabbedPage)element;\n\n\t\t\tif (oldElement != null)\n\t\t\t{\n\t\t\t\toldElement.PropertyChanged -= OnElementPropertyChanged;\n\t\t\t\t((INotifyCollectionChanged)oldElement.Children).CollectionChanged -= OnPagesChanged;\n\t\t\t\tControl?.GetDescendantsByName<TextBlock>(TabBarHeaderTextBlockName).ForEach(t => { t.AccessKeyInvoked -= AccessKeyInvokedForTab; });\n\t\t\t}\n\n\t\t\tif (element != null)\n\t\t\t{\n\t\t\t\tif (Control == null)\n\t\t\t\t{\n\t\t\t\t\tControl = new FormsPivot\n\t\t\t\t\t{\n\t\t\t\t\t\tStyle = (Microsoft.UI.Xaml.Style)Microsoft.UI.Xaml.Application.Current.Resources[\"TabbedPageStyle\"],","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Compatibility/Core/src/Windows/TabbedPageRenderer.cs#L138-L174","documentation":"TabbedPageRenderer.SetElement throws ArgumentException if the element is non-null and not a TabbedPage. The renderer is type-specific and uses TabbedPage.Children for its tab collection and binds to TabbedPage-specific properties.","triggerScenarios":"Explicitly calling SetElement on a TabbedPageRenderer instance with a ContentPage, NavigationPage, or other non-TabbedPage element. Or a misconfigured ExportRenderer attribute mapping TabbedPageRenderer to the wrong element type.","commonSituations":"Copy-paste error in ExportRenderer registration; custom renderer inheriting from TabbedPageRenderer used for a non-tabbed page; framework internals incorrectly routing element to renderer.","solutions":["Verify the element type is TabbedPage before calling SetElement","Check ExportRenderer attributes for correct type-to-renderer mappings","If building a custom tabbed renderer, inherit from the correct base and ensure the element type constraint"],"exampleFix":"// before\nvar renderer = new TabbedPageRenderer();\nrenderer.SetElement(new ContentPage()); // throws\n\n// after\nvar renderer = new TabbedPageRenderer();\nrenderer.SetElement(new TabbedPage { Children = { page1, page2 } }); // works","handlingStrategy":"type-guard","validationCode":"// Before calling SetElement, verify the element type\nif (element != null && !(element is TabbedPage))\n    throw new ArgumentException($\"Expected TabbedPage, got {element.GetType().Name}\");\nrenderer.SetElement(element);","typeGuard":"static bool IsValidElementForTabbedRenderer(VisualElement element)\n{\n    return element == null || element is TabbedPage;\n}","tryCatchPattern":null,"preventionTips":["Verify element type before calling SetElement on type-specific renderers","Check ExportRenderer attributes for correct type-to-renderer mappings","Unit test renderer-element pairings"],"tags":["rendering","type-mismatch","validation","winui","tabbedpage"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}