Ejemplo n.º 1
0
    private void CreateMenuRecursively(SiteMapNodeCollection nodes, ListMenuItemCollection items)
    {
        ListMenuItem item;

        foreach (SiteMapNode node in nodes)
        {
            item = new ListMenuItem(node.Title, node.Url);
            items.Add(item);
            this.CreateMenuRecursively(node.ChildNodes, item.ChildItems);
        }
    }
Ejemplo n.º 2
0
    /// <summary>
    ///  遞歸建立Element
    /// </summary>
    /// <param name="items"></param>
    /// <param name="sb"></param>
    private void BuildElementRecursive(ListMenuItemCollection items, StringBuilder sb, int index)
    {
        string target = string.Empty, className, id, style;

        this.mLevel += 1;
        index++;

        if (items.Count > 0)
        {
            //sb.AppendFormat("<div id=\"{0}\" class=\"{0}\">", this.ID, this.DivClass).AppendLine();
            if (this.mLevel == 1)
            {
                if (string.IsNullOrEmpty(this.ULClass))
                {
                    className = string.Empty;
                }
                else
                {
                    className = string.Format("class=\"{0}\"", this.ULClass);
                }
            }
            else
            {
                className = string.Empty;
            }

            id    = string.IsNullOrEmpty(this.ID) ? "" : string.Format("id=\"{0}\" ", index > 1 ? this.ID + "_" + index : this.ID);
            style = string.IsNullOrEmpty(this.ULStyle) ? "" : string.Format("style=\"{0}\"", this.ULStyle);

            sb.AppendFormat("<ul {0} {1} {2}>", className, id, style).AppendLine();
        }

        foreach (ListMenuItem item in items)
        {
            sb.AppendLine(item.Start());

            //遞歸建立
            this.BuildElementRecursive(item.ChildItems, sb, index);
            sb.AppendLine(item.End());
        }

        if (items.Count > 0)
        {
            sb.AppendLine("</ul>");
            //sb.AppendLine("</div>");
        }
    }
Ejemplo n.º 3
0
 public ListMenu()
 {
     this.mItems      = new ListMenuItemCollection();
     this.Orientation = Orientation.Vertical;
     this.mLevel      = 0;
 }