{"record":{"id":"57f7622176b66bc1","repo":"dotnet/maui","slug":"renderer-must-be-a-page-renderer","errorCode":null,"errorMessage":"renderer must be a Page renderer.","messagePattern":"renderer must be a Page renderer\\.","errorType":"exception","errorClass":"InvalidCastException","httpStatus":null,"severity":"error","filePath":"src/Compatibility/Core/src/iOS/Renderers/TabbedRenderer.cs","lineNumber":469,"sourceCode":"\t\t}\n\n\t\tvoid UpdateCurrentPage()\n\t\t{\n\t\t\tvar count = Tabbed.InternalChildren.Count;\n\t\t\tvar index = (int)SelectedIndex;\n\t\t\t((TabbedPage)Element).CurrentPage = index >= 0 && index < count ? Tabbed.GetPageByIndex(index) : null;\n\t\t}\n\n\t\tvoid IEffectControlProvider.RegisterEffect(Effect effect)\n\t\t{\n\t\t\tVisualElementRenderer<VisualElement>.RegisterEffect(effect, View);\n\t\t}\n\n\t\tasync void SetTabBarItem(IVisualElementRenderer renderer)\n\t\t{\n\t\t\tvar page = renderer.Element as Page;\n\t\t\tif (page == null)\n\t\t\t\tthrow new InvalidCastException($\"{nameof(renderer)} must be a {nameof(Page)} renderer.\");\n\n\t\t\tvar icons = await GetIcon(page);\n\t\t\trenderer.ViewController.TabBarItem = new UITabBarItem(page.Title, icons?.Item1, icons?.Item2)\n\t\t\t{\n\t\t\t\tTag = Tabbed.Children.IndexOf(page),\n\t\t\t\tAccessibilityIdentifier = page.AutomationId\n\t\t\t};\n\t\t\ticons?.Item1?.Dispose();\n\t\t\ticons?.Item2?.Dispose();\n\t\t}\n\n\t\tvoid UpdateSelectedTabColors()\n\t\t{\n\t\t\tif (Tabbed == null || TabBar == null || TabBar.Items == null)\n\t\t\t\treturn;\n\n\t\t\tif (Tabbed.IsSet(TabbedPage.SelectedTabColorProperty) && Tabbed.SelectedTabColor != null)\n\t\t\t{","sourceCodeStart":451,"sourceCodeEnd":487,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Compatibility/Core/src/iOS/Renderers/TabbedRenderer.cs#L451-L487","documentation":"In TabbedRenderer.SetTabBarItem, the renderer's Element is cast to Page (line 471: 'var page = renderer.Element as Page;'). Only Page-derived elements belong in a TabbedPage's children. If the cast fails (Element is not a Page), an InvalidCastException is thrown with a clear message, because the tab bar item (title/icon/automation id) requires a Page.","triggerScenarios":"Adding a non-Page VisualElement as a child of a TabbedPage, or a custom renderer reporting a non-Page Element. TabbedPage.Children should only contain Page instances.","commonSituations":"Mistakenly adding a layout/ContentView directly to TabbedPage.Children instead of wrapping it in a ContentPage; custom renderers that swap the Element to a non-Page type; binding a TabbedPage to a source yielding non-Page items.","solutions":["Ensure every child of TabbedPage is a Page subclass (ContentPage, NavigationPage, etc.).","Wrap non-page content in a ContentPage before adding to Children.","Validate ItemsSource element types when data-binding a TabbedPage."],"exampleFix":"// before\ntabbedPage.Children.Add(new StackLayout()); // not a Page\n\n// after\nvar page = new ContentPage { Content = new StackLayout() };\ntabbedPage.Children.Add(page);","handlingStrategy":"type-guard","validationCode":"foreach (var child in tabbedPage.Children)\n    if (!(child is Page)) throw new InvalidOperationException($\"{child} is not a Page\");","typeGuard":"static bool IsValidTabChild(object element) => element is Page;","tryCatchPattern":null,"preventionTips":["Only add Page-derived instances to TabbedPage.Children.","Wrap non-page content in ContentPage.","Validate bound ItemsSource element types."],"tags":["invalidcastexception","ios","tabbedpage","children","type-mismatch"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}