コード例 #1
0
        public override void Add(SimpleActionItem item)
        {
            var menu = new IconMenuItem(item.Caption, item.SmallImage, (sender, e) => item.OnClick(e))
            {Name = item.Key, Enabled = item.Enabled, Visible = item.Visible,};
            item.PropertyChanged += SimpleActionItem_PropertyChanged;

            EnsureNonNullRoot(item);

            MenuItem root;
            if (item.MenuContainerKey == null)
            {
                root = !mainmenu.MenuItems.ContainsKey(item.RootKey)
                    ? mainmenu.MenuItems[mainmenu.MenuItems.Add(new MenuItem(item.RootKey) {Name = item.RootKey})]
                    : mainmenu.MenuItems.Find(item.RootKey, true)[0];
            }
            else
            {
                root = mainmenu.MenuItems.Find(item.MenuContainerKey, true)[0];
            }

            root.MenuItems.Add(menu);
        }
コード例 #2
0
ファイル: Legend.cs プロジェクト: DIVEROVIEDO/DotSpatial
        /// <summary>
        /// Recursive add method to handle nesting of menu items.
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="mi"></param>
        private static void AddMenuItem(Menu.MenuItemCollection parent, SymbologyMenuItem mi)
        {
            MenuItem m;
            if (mi.Icon != null)
            {
                m = new IconMenuItem(mi.Name, mi.Icon, mi.ClickHandler);
            }
            else if (mi.Image != null)
            {
                m = new IconMenuItem(mi.Name, mi.Image, mi.ClickHandler);
            }
            else
            {
                m = new IconMenuItem(mi.Name, mi.ClickHandler);
            }

            parent.Add(m);
            foreach (SymbologyMenuItem child in mi.MenuItems)
            {
                AddMenuItem(m.MenuItems, child);
            }
        }