示例#1
0
        /// <summary>
        /// Event handler registered on each MenuItem to allow the TopMenu to manage which items
        /// are selected and to bubble the event up to the NavigationMenu.
        /// </summary>
        /// <param name="menuItem">The MenuItem that evoked the event being handled.</param>
        public void MenuItemEventListener(MenuItem menuItem)
        {
            // De-select the old item
            this._selectedItem.IsSelected = false;

            // Set the new item as the selected item
            this._selectedItem = menuItem;

            // Set the newly selected item to selected
            this._selectedItem.IsSelected = true;

            // Bubble the event up
            this._topMenuEvent(this, TopMenuEventType.MENUITEM_SELECTED);
        }
示例#2
0
        /// <summary>
        /// Add another MenuItem to this TopMenu
        /// </summary>
        /// <param name="menuItem">The new MenuItem to be added.</param>
        public void AddMenuItem(MenuItem menuItem)
        {
            // Get an Enumerator for the collection of MenuItems
            IEnumerator<MenuItem> menuItemsEnum = this._menuItems.GetEnumerator();

            // Determine if an item already exists with the new item's ID
            while (menuItemsEnum.MoveNext())
            {
                // If it does, throw an exception and quit
                if (menuItemsEnum.Current.Id.Equals(menuItem.Id))
                {
                    menuItemsEnum.Dispose();
                    throw new ApplicationException("Attempting to add MenuItem with non-unique ID.");
                }
            }

            // Attach this TopMenu's MenuItemEvent handler to the MenuItem's event so the TopMenu
            // may respond to it.
            menuItem.AddMenuItemEventListener(this.MenuItemEventListener);

            // If no matches are found, add the new item
            this._menuItems.Add(menuItem);

            // If this was the first item, set it as the selected item
            if (this._menuItems.Count == 1)
            {
                // Set the MenuItem as selected
                menuItem.IsSelected = true;

                // Store a reference to the selected item for this TopMenu
                this._selectedItem = menuItem;
            }

            // Trigger a TopMenuEvent
            if (this._topMenuEvent != null)
            {
                this._topMenuEvent(this, TopMenuEventType.MENU_MODIFIED);
            }
        }