{"record":{"id":"c446897e8a550339","repo":"MahApps/MahApps.Metro","slug":"optionslistview-is-not-defined-yet-please-use-opt","errorCode":null,"errorMessage":"OptionsListView is not defined yet. Please use OptionsItemsSource instead.","messagePattern":"OptionsListView is not defined yet\\. Please use OptionsItemsSource instead\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/MahApps.Metro/Controls/HamburgerMenu/HamburgerMenu.Options.cs","lineNumber":171,"sourceCode":"        public object? OptionsItemCommandParameter\n        {\n            get => this.GetValue(OptionsItemCommandParameterProperty);\n            set => this.SetValue(OptionsItemCommandParameterProperty, value);\n        }\n\n        /// <summary>\n        /// Gets the collection used to generate the content of the option list.\n        /// </summary>\n        /// <exception cref=\"Exception\">\n        /// Exception thrown if OptionsListView is not yet defined.\n        /// </exception>\n        public ItemCollection OptionsItems\n        {\n            get\n            {\n                if (this.optionsListView is null)\n                {\n                    throw new Exception(\"OptionsListView is not defined yet. Please use OptionsItemsSource instead.\");\n                }\n\n                return this.optionsListView.Items;\n            }\n        }\n\n        /// <summary>\n        /// Executes the <see cref=\"OptionsItemCommand\"/>.\n        /// </summary>\n        public void RaiseOptionsItemCommand()\n        {\n            var command = this.OptionsItemCommand;\n            var commandParameter = this.OptionsItemCommandParameter ?? this;\n            if (command != null && command.CanExecute(commandParameter))\n            {\n                command.Execute(commandParameter);\n            }\n        }","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/MahApps/MahApps.Metro/blob/72099e310bac2d12ac98fd7560b69679252519f5/src/MahApps.Metro/Controls/HamburgerMenu/HamburgerMenu.Options.cs#L153-L189","documentation":"Thrown by the HamburgerMenu.OptionsItems getter when optionsListView is null. The OptionsListView is a template part resolved in OnApplyTemplate via GetTemplateChild(\"OptionsListView\"); it is null when the control's ControlTemplate does not define that part, or when OptionsItems is accessed before the template is applied. The message directs users to OptionsItemsSource, which works without the template part.","triggerScenarios":"Using a custom HamburgerMenu ControlTemplate that omits the 'OptionsListView' ListBox; reading OptionsItems during construction before OnApplyTemplate runs; accessing OptionsItems in XAML code-behind before the control Loaded.","commonSituations":"Custom hamburger template for a sidebar without the options region; accessing OptionsItems in a constructor or InitializeComponent path; design-time access.","solutions":["Use the OptionsItemsSource property (bound in XAML) instead of the OptionsItems collection, as it does not require the template part.","Ensure the HamburgerMenu ControlTemplate includes a ListBox named 'OptionsListView'.","Access OptionsItems only after the control's Loaded event (OnApplyTemplate has run).","Null-check or use the default HamburgerMenu template."],"exampleFix":"<!-- before: reading the collection in code too early / missing template -->\n<controls:HamburgerMenu x:Name=\"Menu\" />  // menu.OptionsItems accessed in ctor -> throws\n\n<!-- after: bind via ItemsSource instead -->\n<controls:HamburgerMenu OptionsItemsSource=\"{Binding OptionCommands}\" />","handlingStrategy":"validation","validationCode":"// Prefer binding via ItemsSource; only touch the collection after Loaded.\nif (menu.IsLoaded)\n{\n    var items = menu.OptionsItems; // safe after template applied\n}\n// In XAML, bind instead: OptionsItemsSource=\"{Binding ...}\"","typeGuard":"static bool HasOptionsListView(HamburgerMenu m)\n    => m.IsLoaded && m.Template.FindName(\"OptionsListView\", m) is ListBox;","tryCatchPattern":"try { var items = menu.OptionsItems; }\ncatch (Exception ex) when (ex.Message.Contains(\"OptionsListView is not defined\"))\n{\n    // Template missing the part; switch to OptionsItemsSource binding.\n}","preventionTips":["Bind OptionsItemsSource in XAML rather than touching OptionsItems in code.","Ensure the HamburgerMenu ControlTemplate includes a ListBox named 'OptionsListView'.","Access OptionsItems 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"}