{"record":{"id":"82014b2c6f2f1389","repo":"MahApps/MahApps.Metro","slug":"buttonslistview-is-not-defined-yet-please-use-ite","errorCode":null,"errorMessage":"ButtonsListView is not defined yet. Please use ItemsSource instead.","messagePattern":"ButtonsListView is not defined yet\\. Please use ItemsSource instead\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/MahApps.Metro/Controls/HamburgerMenu/HamburgerMenu.Properties.cs","lineNumber":572,"sourceCode":"        public Style? ItemFocusVisualStyle\n        {\n            get => (Style?)this.GetValue(ItemFocusVisualStyleProperty);\n            protected set => this.SetValue(ItemFocusVisualStylePropertyKey, value);\n        }\n\n        /// <summary>\n        /// Gets the collection used to generate the content of the items list.\n        /// </summary>\n        /// <exception cref=\"Exception\">\n        /// Exception thrown if ButtonsListView is not yet defined.\n        /// </exception>\n        public ItemCollection Items\n        {\n            get\n            {\n                if (this.buttonsListView is null)\n                {\n                    throw new Exception(\"ButtonsListView is not defined yet. Please use ItemsSource instead.\");\n                }\n\n                return this.buttonsListView.Items;\n            }\n        }\n\n        /// <summary>\n        /// Executes the <see cref=\"ItemCommand\"/>.\n        /// </summary>\n        public void RaiseItemCommand()\n        {\n            var command = this.ItemCommand;\n            var commandParameter = this.ItemCommandParameter ?? this;\n            if (command != null && command.CanExecute(commandParameter))\n            {\n                command.Execute(commandParameter);\n            }\n        }","sourceCodeStart":554,"sourceCodeEnd":590,"githubUrl":"https://github.com/MahApps/MahApps.Metro/blob/72099e310bac2d12ac98fd7560b69679252519f5/src/MahApps.Metro/Controls/HamburgerMenu/HamburgerMenu.Properties.cs#L554-L590","documentation":"Thrown by the HamburgerMenu.Items getter when buttonsListView is null. ButtonsListView is the template part resolved in OnApplyTemplate via GetTemplateChild(\"ButtonsListView\"); null means the ControlTemplate lacks that part or Items was accessed before the template applied. The message points to ItemsSource, which works without the template part.","triggerScenarios":"Custom HamburgerMenu ControlTemplate missing a ListBox named 'ButtonsListView'; accessing Items in the constructor or before Loaded; design-time/code-gen access to Items.","commonSituations":"Heavily customized hamburger template that removed the main list view; accessing Items during InitializeComponent; using Items.Add in code before the template is live.","solutions":["Use the ItemsSource property (bind in XAML) instead of the Items collection.","Ensure the HamburgerMenu ControlTemplate declares a ListBox named 'ButtonsListView'.","Access Items only after the control's Loaded event.","Use the default HamburgerMenu template."],"exampleFix":"<!-- before: code-behind menu.Items.Add(...) before template applied -->\n\n<!-- after: bind the source -->\n<controls:HamburgerMenu ItemsSource=\"{Binding MenuItems}\" />","handlingStrategy":"validation","validationCode":"// Prefer ItemsSource binding; only read Items after Loaded.\nif (menu.IsLoaded)\n{\n    var items = menu.Items; // safe after template applied\n}\n// In XAML: ItemsSource=\"{Binding ...}\"","typeGuard":"static bool HasButtonsListView(HamburgerMenu m)\n    => m.IsLoaded && m.Template.FindName(\"ButtonsListView\", m) is ListBox;","tryCatchPattern":"try { var items = menu.Items; }\ncatch (Exception ex) when (ex.Message.Contains(\"ButtonsListView is not defined\"))\n{\n    // Template missing the part; switch to ItemsSource binding.\n}","preventionTips":["Bind ItemsSource in XAML rather than touching Items in code.","Ensure the HamburgerMenu ControlTemplate includes a ListBox named 'ButtonsListView'.","Access Items only after Loaded."],"tags":["wpf","hamburger-menu","mahapps","template","data-binding"],"backgroundTag":null,"analyzedSha":"72099e310bac2d12ac98fd7560b69679252519f5","analyzedAt":"2026-08-13T20:19:34.419Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}