예제 #1
0
        /// <summary>
        /// Overrides SelectStyle function and returns proper style element base on menutext.
        /// </summary>
        /// <param name="item"><see cref="MenuDataItem"/> for which style is to be determined.</param>
        /// <param name="container"><see cref="FrameworkElement"/> containing <see cref="MenuDataItem"/>.</param>
        /// <returns><see cref="Style"/> based on MenuText.</returns>
        public override Style SelectStyle(object item, DependencyObject container)
        {
            FrameworkElement frameworkElement = container as FrameworkElement;
            MenuDataItem     menuDataItem     = item as MenuDataItem;

            if (((object)frameworkElement != null) && ((object)menuDataItem != null))
            {
                if (string.IsNullOrEmpty(menuDataItem.MenuText))
                {
                    return(frameworkElement.FindResource("MenuSeparatorStyle") as Style);
                }
                else
                {
                    return(frameworkElement.FindResource("MenuItemStyle") as Style);
                }
            }

            return(null);
        }
        /// <summary>
        /// Handles click event of the buttons on the screen.
        /// </summary>
        /// <param name="sender">Source of the event.</param>
        /// <param name="e">Event arguments.</param>
        private void CommonClickHandler(object sender, RoutedEventArgs e)
        {
            MenuDataItem item = new MenuDataItem();
            string stringToMatch = ((Button)sender).Tag.ToString();

            if (!string.IsNullOrEmpty(stringToMatch))
            {
                if (stringToMatch == "Restart")
                {
                    RestartService();
                }
                else
                {
                    GetMenuDataItem(m_menuDataItems, stringToMatch, ref item);

                    if ((object)item.MenuText != null)
                        item.Command.Execute(null);
                }
            }
        }
        /// <summary>
        /// Recursively finds menu item to navigate to when a button is clicked on the UI.
        /// </summary>
        /// <param name="items">Collection of menu items.</param>
        /// <param name="stringToMatch">Item to search for in menu items collection.</param>
        /// <param name="item">Returns a menu item.</param>
        private void GetMenuDataItem(ObservableCollection<MenuDataItem> items, string stringToMatch, ref MenuDataItem item)
        {
            for (int i = 0; i < items.Count; i++)
            {
                if (items[i].UserControlPath.ToLower() == stringToMatch.ToLower())
                {
                    item = items[i];
                    break;
                }

                if (items[i].SubMenuItems.Count > 0)
                    GetMenuDataItem(items[i].SubMenuItems, stringToMatch, ref item);
            }
        }