{"record":{"id":"df4cdbaa56b3ec86","repo":"dotnet/wpf","slug":"sr-toolbar-invalidstyle-toolbaroverflowpanel","errorCode":null,"errorMessage":"SR.ToolBar_InvalidStyle_ToolBarOverflowPanel","messagePattern":"SR\\.ToolBar_InvalidStyle_ToolBarOverflowPanel","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ToolBar.cs","lineNumber":619,"sourceCode":"        /// Gets reference to ToolBar's ToolBarOverflowPanel element.\n        /// </summary>\n        internal ToolBarOverflowPanel ToolBarOverflowPanel\n        {\n            get\n            {\n                if (_toolBarOverflowPanel == null)\n                    _toolBarOverflowPanel = FindToolBarOverflowPanel();\n\n                return _toolBarOverflowPanel;\n            }\n        }\n\n        private ToolBarOverflowPanel FindToolBarOverflowPanel()\n        {\n            DependencyObject child = GetTemplateChild(ToolBarOverflowPanelTemplateName);\n            ToolBarOverflowPanel toolBarOverflowPanel = child as ToolBarOverflowPanel;\n            if (child != null && toolBarOverflowPanel == null)\n                throw new NotSupportedException(SR.Format(SR.ToolBar_InvalidStyle_ToolBarOverflowPanel, child.GetType()));\n            return toolBarOverflowPanel;\n        }\n\n        /// <summary>\n        /// This is the method that responds to the KeyDown event.\n        /// </summary>\n        /// <param name=\"e\"></param>\n        protected override void OnKeyDown(KeyEventArgs e)\n        {\n            UIElement newFocusElement = null;\n            UIElement currentFocusElement = e.Source as UIElement;\n            if (currentFocusElement != null && ItemsControl.ItemsControlFromItemContainer(currentFocusElement) == this)\n            {\n                // itemsHost should be either ToolBarPanel or ToolBarOverflowPanel\n                Panel itemsHost = VisualTreeHelper.GetParent(currentFocusElement) as Panel;\n                if (itemsHost != null)\n                {\n                    switch (e.Key)","sourceCodeStart":601,"sourceCodeEnd":637,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ToolBar.cs#L601-L637","documentation":"ToolBar.FindToolBarOverflowPanel looks up the template child named ToolBarOverflowPanelTemplateName and requires it to be a ToolBarOverflowPanel. If a template element with that name has a different type, it throws NotSupportedException (SR.ToolBar_InvalidStyle_ToolBarOverflowPanel) naming the actual type. ToolBar needs this specific panel type for its overflow drop-down behavior.","triggerScenarios":"Applying a custom ControlTemplate for ToolBar that declares a child named \"PART_ToolBarOverflowPanel\" whose type is not ToolBarOverflowPanel (e.g. a StackPanel, DockPanel, or ContentPresenter).","commonSituations":"Custom themes/restyled ToolBars where the overflow panel was swapped for a simpler panel; template refactoring tools or copy-paste edits renaming elements; learning templates from older themes that are then modified.","solutions":["Ensure the template child named PART_ToolBarOverflowPanel is of type ToolBarOverflowPanel.","Remove or rename the incorrectly typed element so it does not claim the required template-part name.","Restore the part structure from the default ToolBar template shipped with the active theme."],"exampleFix":"<!-- before -->\n<ControlTemplate TargetType=\"ToolBar\">\n  ...\n  <StackPanel x:Name=\"PART_ToolBarOverflowPanel\"/>\n</ControlTemplate>\n\n<!-- after -->\n<ControlTemplate TargetType=\"ToolBar\">\n  ...\n  <ToolBarOverflowPanel x:Name=\"PART_ToolBarOverflowPanel\"/>\n</ControlTemplate>","handlingStrategy":"validation","validationCode":"// Validate after template application\nvar overflow = template.FindName(\"PART_ToolBarOverflowPanel\", toolBar) as ToolBarOverflowPanel;\nif (overflow == null) throw new InvalidOperationException(\"Template must declare PART_ToolBarOverflowPanel as ToolBarOverflowPanel\");","typeGuard":"bool ok = VisualTreeHelper.GetChild(toolBar, i) is ToolBarOverflowPanel;","tryCatchPattern":"try\n{\n    toolBar.ApplyTemplate();\n}\ncatch (NotSupportedException ex)\n{\n    // log template part type error; revert to default ToolBar style\n}","preventionTips":["Keep PART_ToolBarOverflowPanel typed as ToolBarOverflowPanel in any ToolBar template.","Never rename/replace template parts with differently-typed elements during restyling.","Review custom themes against the default theme's template parts before release."],"tags":["wpf","xaml","control-template","toolbar","template-parts"],"backgroundTag":"type-mismatch","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}