private static BaseMenuItem GetMenuByAction(string action, Collection <object> sourceMenus)
 {
     if (sourceMenus != null)
     {
         foreach (object item in sourceMenus)
         {
             if (item is CompositeMenuItem)
             {
                 CompositeMenuItem compositeMenuItem = ((CompositeMenuItem)item);
                 BaseMenuItem      menu = GetMenuByAction(action, compositeMenuItem.Children);
                 if (menu != null)
                 {
                     return(menu);
                 }
             }
             else if (item is SingleMenuItem)
             {
                 SingleMenuItem singleMenuItem = ((SingleMenuItem)item);
                 if (string.Compare(singleMenuItem.Action, action, StringComparison.InvariantCultureIgnoreCase) == 0)
                 {
                     return(singleMenuItem);
                 }
             }
         }
     }
     return(null);
 }
        private static Collection <BaseMenuItem> GetMenusByGroupName(string groupName, Collection <object> sourceMenus)
        {
            var menus = new Collection <BaseMenuItem>();

            if (sourceMenus != null)
            {
                foreach (object item in sourceMenus)
                {
                    if (item is CompositeMenuItem)
                    {
                        CompositeMenuItem         compositeMenuItem = ((CompositeMenuItem)item);
                        Collection <BaseMenuItem> recursions        = GetMenusByGroupName(groupName, compositeMenuItem.Children);
                        foreach (BaseMenuItem recursionItem in recursions)
                        {
                            menus.Add(recursionItem);
                        }
                    }
                    else if (item is SingleMenuItem)
                    {
                        SingleMenuItem singleMenuItem = ((SingleMenuItem)item);
                        if (string.Compare(singleMenuItem.GroupName, groupName, StringComparison.InvariantCultureIgnoreCase) == 0)
                        {
                            menus.Add((BaseMenuItem)item);
                        }
                    }
                }
            }
            return(menus);
        }
 private void SwitchCheckedState(BaseMenuItem menuItem, IEnumerable <object> menuItems)
 {
     if (menuItems != null)
     {
         IEnumerator <object> enumerator = menuItems.GetEnumerator();
         while (enumerator.MoveNext())
         {
             object current = enumerator.Current;
             if (current is SingleMenuItem)
             {
                 SingleMenuItem singleMenuItem = (SingleMenuItem)current;
                 if (singleMenuItem.GroupName == menuItem.GroupName &&
                     singleMenuItem.IsCheckable &&
                     !singleMenuItem.CanToggle)
                 {
                     singleMenuItem.IsChecked = singleMenuItem == menuItem;
                 }
             }
         }
     }
 }