コード例 #1
0
ファイル: CustomMenu.cs プロジェクト: aomiit/caisis
        /// <summary>
        /// Recursively binds a
        /// </summary>
        /// <param name="list"></param>
        /// <param name="node"></param>
        private void RecursiveMenuBind(MenuList list, XmlNode node)
        {
            // Only bind Element nodes, not comments
            if (pedc.IsDisplayInMainMenu(node) && pedc.IsDisplayInView(node) && node.NodeType == XmlNodeType.Element)
            {
                MenuListItem Item = GetFormattedListItem(node);
                list.Controls.Add(Item);
                if (node.HasChildNodes)
                {
                    howdeep++;
                    if (howdeep < DEPTH || DEPTH < 0)
                    {
                        MenuList SubMenu = new MenuList();
                        Item.Controls.Add(SubMenu);
                        foreach (XmlNode child in node.ChildNodes)
                        {
                            RecursiveMenuBind(SubMenu, child);
                            AddLinkStyle(SubMenu);
                        }
                        // Logic to set static heights and overflow
                        // Need to set widths inline to prevent collapsing in som DOM browsers
                        if (!string.IsNullOrEmpty(StaticHeight) && SubMenu.Controls.Count > 20)
                        {
                            SubMenu.Style.Add("height", StaticHeight + "px");
                            if (SubMenu.Controls[0] is MenuListItem)
                            {
                                if (SubMenu.Controls[0].HasControls())
                                {
                                    if (SubMenu.Controls[0].Controls[0] is HyperLink)
                                    {
                                        string width = ((HyperLink)SubMenu.Controls[0].Controls[0]).Style["width"];
                                        if (!string.IsNullOrEmpty(width))
                                        {
                                            string subMenuWidth = int.Parse(width.Replace("em", "")) + 2 + "em";
                                            SubMenu.Style.Add("width", subMenuWidth);
                                        }
                                    }
                                }
                            }
                            SubMenu.Style.Add("overflow", "auto");
                        }

                        if (!SubMenu.HasControls() && SubMenu.Parent != null)
                        {
                            SubMenu.Parent.Controls.Remove(SubMenu);
                        }
                    }
                    howdeep--;
                }
            }
        }