private Accordion InitAccordionMenu() { Accordion accordionMenu = new Accordion(); accordionMenu.ID = "accordionMenu"; accordionMenu.EnableFill = true; accordionMenu.ShowBorder = false; accordionMenu.ShowHeader = false; Region2.Items.Add(accordionMenu); XmlDocument xmlDoc = XmlDataSource1.GetXmlDocument(); XmlNodeList xmlNodes = xmlDoc.SelectNodes("/Tree/TreeNode"); foreach (XmlNode xmlNode in xmlNodes) { if (xmlNode.HasChildNodes) { AccordionPane accordionPane = new AccordionPane(); accordionPane.Title = xmlNode.Attributes["Text"].Value; accordionPane.Layout = Layout.Fit; accordionPane.ShowBorder = false; accordionPane.BodyPadding = "2px 0 0 0"; accordionMenu.Items.Add(accordionPane); Tree innerTree = new Tree(); innerTree.EnableArrows = true; innerTree.ShowBorder = false; innerTree.ShowHeader = false; innerTree.EnableIcons = false; innerTree.AutoScroll = true; accordionPane.Items.Add(innerTree); XmlDocument innerXmlDoc = new XmlDocument(); innerXmlDoc.LoadXml(String.Format("<?xml version=\"1.0\" encoding=\"utf-8\" ?><Tree>{0}</Tree>", xmlNode.InnerXml)); // 绑定AccordionPane内部的树控件 innerTree.DataSource = innerXmlDoc; innerTree.DataBind(); // 重新设置每个节点的图标 ResolveTreeNode(innerTree.Nodes); } } return accordionMenu; }
/// <summary> /// 构造函数 /// </summary> /// <param name="accordion">手风琴实例</param> public AccordionPaneCollection(Accordion accordion) { _accordion = accordion; }
protected override void OnFirstPreRender() { base.OnFirstPreRender(); #region Check Parent Accordion parentControl = Parent as Accordion; if (parentControl == null) { throw new Exception("AccordionPane must inside the control Accordion!"); } #endregion #region AutoHeight // 如果要充满整个Accordion,则设置每个AccordionPanel的AutoHeight=false if (parentControl.EnableFill) { OB.AddProperty("autoHeight", false); } #endregion string renderScript = String.Empty; #region Hover/Select // 如果启用高亮显示选中的,则在每个AccordionPanel的折叠展开时都要改变高亮选中的状态 if (EnableLargeHeader && EnableHightlight) { renderScript += String.Format("{0}.header.addClassOnOver('{1}');", XID, ACCORDION_HEADER_HOVER); // 如果这个AccordionPanel需要高亮显示 if (parentControl.ActiveIndex >= 0 && parentControl.ActiveIndex < parentControl.Panes.Count) { if (parentControl.Panes[parentControl.ActiveIndex] == this) { //OB.AddProperty(OptionName.Cls, ACCORDION_BIG_HEADER_SELECT_CLASS); renderScript += String.Format("{0}.header.addClass('{1}');", XID, ACCORDION_HEADER_SELECT); } } OB.Listeners.RemoveProperty("collapse"); OB.Listeners.RemoveProperty("expand"); OB.Listeners.AddProperty("collapse", String.Format("function(panel){{Ext.get('{0}').dom.value=true;X.{1}.header.removeClass('{2}');}}", CollapsedHiddenFieldID, XID, ACCORDION_HEADER_SELECT), true); OB.Listeners.AddProperty("expand", String.Format("function(panel){{Ext.get('{0}').dom.value=false;X.{1}.header.addClass('{2}');}}", CollapsedHiddenFieldID, XID, ACCORDION_HEADER_SELECT), true); } #endregion #region Links //if (Links.Count > 0) //{ // OB.RemoveProperty("items"); // StringBuilder sb = new StringBuilder(); // sb.Append("<ul class=\"box-accrodion-link-ul\">"); // foreach (AccordionLink link in Links) // { // #region li // HtmlNodeBuilder nb = new HtmlNodeBuilder("a"); // nb.SetProperty("id", link.ClientID); // if (!String.IsNullOrEmpty(link.OnClientClick)) // { // nb.SetProperty("onclick", String.Format("javascript:{0}", link.OnClientClick)); // } // if (!String.IsNullOrEmpty(link.NavigateUrl)) // { // nb.SetProperty("href", ResolveUrl(link.NavigateUrl)); // if (!String.IsNullOrEmpty(link.Target)) // { // nb.SetProperty("target", link.Target); // } // } // nb.SetProperty("style", "display:block;cursor:pointer;"); // string content = String.Empty; // if (!String.IsNullOrEmpty(link.IconUrl)) // { // content += String.Format("<img src=\"{0}\" align=\"bottom\" alt=\"\" />", ResolveUrl(link.IconUrl)); // } // content += " " + link.Text; // nb.InnerProperty = content; // #endregion // sb.AppendFormat("<li {1}>{0}</li>", nb.ToString(), link.Selected ? "class=\"box-accrodion-link-select\"" : ""); // } // sb.Append("</ul>"); // OB.AddProperty("html", sb.ToString()); // // 注册所有链接的脚本 // // 所有的li,鼠标移动上去是一种样式,鼠标移开又是另外一种样式 // string hoverScript = "ele = Ext.get(ele);"; // hoverScript += "ele.on('mouseover',function(){Ext.get(this.findParentNode('li')).addClass('box-accrodion-link-hover');},ele);"; // hoverScript += "ele.on('mouseout',function(){Ext.get(this.findParentNode('li')).removeClass('box-accrodion-link-hover');},ele);"; // //string clickScript = String.Empty; // //clickScript += String.Format("Ext.each(X.{0}.el.query('ul.box-accrodion-link-ul li'),function(ele){{Ext.get(ele).removeClass('box-accrodion-link-select');}});", parentControl.ClientJavascriptID); // //clickScript += "Ext.get('{0}').addClass('box-accrodion-link-select');"; // string clickScript = String.Format("function(){{X.{0}.box_active(ele.id);}}", parentControl.XID); // hoverScript += "ele.on('click'," + clickScript + ");"; // renderScript += String.Format("Ext.each(X.{0}.el.query('ul.box-accrodion-link-ul li a'),function(ele){{{1}}});", XID, hoverScript); //} #endregion if (!String.IsNullOrEmpty(renderScript)) { renderScript = JsHelper.GetDeferScript(renderScript, 100); OB.Listeners.AddProperty("render", JsHelper.GetFunction(renderScript, "component"), true); } string jsContent = String.Format("var {0}=new Ext.Panel({1});", XID, OB.ToString()); AddStartupScript(jsContent); }