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 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);
 }
 protected BaseMenuItem(string icon, string header, string action, string groupName, bool isCheckEnabled, bool isChecked, bool canToggle, CompositeMenuItem parent)
 {
     Icon        = icon;
     Header      = header;
     Action      = action;
     GroupName   = groupName;
     IsCheckable = isCheckEnabled;
     IsChecked   = isChecked;
     CanToggle   = canToggle;
     Parent      = parent;
 }
        private static void Parse(XmlNode xmlNode, CompositeMenuItem menu)
        {
            switch (xmlNode.Name.ToLower())
            {
            case "menu":
            {
                CompositeMenuItem compositeMenuItem = new CompositeMenuItem(xmlNode.Attributes["header"].Value, new Collection <object>());
                compositeMenuItem.Parent = menu;
                XmlNode node = xmlNode.SelectSingleNode("menuItems");
                Parse(node, compositeMenuItem);
                menu.Children.Add(compositeMenuItem);
            }
            break;

            case "menuitems":
            {
                XmlNodeList childNodes = xmlNode.ChildNodes;
                foreach (XmlNode node in childNodes)
                {
                    Parse(node, menu);
                }
            }
            break;

            case "menuitem":
            {
                XmlAttributeCollection attrs = xmlNode.Attributes;
                bool isCheckEnabled          = attrs["isCheckable"] != null?Convert.ToBoolean(attrs["isCheckable"].Value) : false;

                bool isChecked = attrs["isChecked"] != null?Convert.ToBoolean(attrs["isChecked"].Value) : false;

                bool canToggle = attrs["canToggle"] != null?Convert.ToBoolean(attrs["canToggle"].Value) : false;

                string icon = attrs["icon"] != null ? attrs["icon"].Value : string.Empty;
                menu.Children.Add(new SingleMenuItem(icon, attrs["header"].Value, attrs["action"].Value, attrs["groupName"].Value, isCheckEnabled, isChecked, canToggle, menu));
            }
            break;

            case "separator":
            {
                menu.Children.Add(new Separator());
            }
            break;

            default:
                break;;
            }
        }
        public static Collection <object> GetMenus()
        {
            XmlDocument doc    = new XmlDocument();
            Stream      stream = App.GetResourceStream(new Uri("pack://application:,,,/resource/menus.xml")).Stream;

            doc.Load(stream);

            XmlNode     root      = doc.SelectSingleNode("menuSet");
            XmlNodeList menuNodes = root.ChildNodes;

            CompositeMenuItem compositeMenuItem = new CompositeMenuItem("root", new Collection <object>());

            foreach (XmlNode menu in menuNodes)
            {
                Parse(menu, compositeMenuItem);
            }
            return(compositeMenuItem.Children);
        }