TemplateBuilder

http://msdn.microsoft.com/zh-cn/vstudio/system.web.ui.templatebuilder_members(VS.85).aspx

 

 TemplateBuilder 成员
TemplateBuilder 成员

支持在生成模板及其包含的子控件时使用的页分析器。

下表列出了由 TemplateBuilder 类型公开的成员。

  名称 说明
公共方法 TemplateBuilder 初始化 TemplateBuilder 类的新实例。
页首
(请参见 受保护的属性
  名称 说明
公共属性 BindingContainerType  获取此生成器所创建控件的绑定容器的类型。(从 ControlBuilder 继承)
公共属性 ControlType  获取要创建的控件的 Type。(从 ControlBuilder 继承)
公共属性 CurrentFilterResolutionService  获取一个 IFilterResolutionService 对象,在设计器中分析和保持控件时使用该对象管理与设备筛选器相关的服务。(从 ControlBuilder 继承)
公共属性 DeclareType  获取代码生成将用于声明控件的类型。(从 ControlBuilder 继承)
公共属性 HasAspCode  获取一个值,该值指示控件是否包含任何代码块。(从 ControlBuilder 继承)
公共属性 ID  获取或设置要生成的控件的标识符属性。(从 ControlBuilder 继承)
公共属性 Localize  获取一个布尔值,该值指示由此 ControlBuilder 对象所创建的控件是否已本地化。(从 ControlBuilder 继承)
公共属性 NamingContainerType  获取此生成器所创建控件的命名容器的类型。(从 ControlBuilder 继承)
公共属性 ServiceProvider  获取此 ControlBuilder 对象的服务对象。(从 ControlBuilder 继承)
公共属性 TagName  获取要生成的控件的标记名称。(从 ControlBuilder 继承)
公共属性 Text 获取或设置模板的开始和结束标记之间的文本。
公共属性 ThemeResolutionService  获取一个 IThemeResolutionService 对象,该对象用于在设计时管理控件的主题和外观。(从 ControlBuilder 继承)
页首
  名称 说明
受保护的属性 FChildrenAsProperties  确定该控件是否有 ChildrenAsProperties 设置为 trueParseChildrenAttribute。(从 ControlBuilder 继承)
受保护的属性 FIsNonParserAccessor  确定控件是否实现 IParserAccessor 接口。(从 ControlBuilder 继承)
受保护的属性 InDesigner  返回 ControlBuilder 是否正在设计器中运行。(从 ControlBuilder 继承)
受保护的属性 InPageTheme  获取一个布尔值,该值指示此 ControlBuilder 对象是否用于生成页主题。(从 ControlBuilder 继承)
受保护的属性 Parser  获取负责分析控件的 TemplateParser。(从 ControlBuilder 继承)

// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Permissive License.
// See http://www.microsoft.com/resources/sharedsource/licensingbasics/sharedsourcelicenses.mspx.
// All other rights reserved.

using System;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Text;
using System.Web.UI.WebControls;
using System.Web.UI;
using System.Web.UI.Design;
using System.Web.UI.Design.WebControls;

namespace AjaxControlToolkit
{
    /// <summary>
    /// Simple read-only designer for the Accordion control
    /// </summary>
    [SuppressMessage("Microsoft.Security", "CA2117:AptcaTypesShouldOnlyExtendAptcaBaseTypes", Justification = "Security handled by base class")]
    public class AccordionDesigner : ControlDesigner
    {
        /// <summary>
        /// Reference to the Accordion control we're designing
        /// </summary>
        private Accordion _accordion;

        /// <summary>
        /// Initializes a new instances of the AccordionDesigner class
        /// </summary>
        [SuppressMessage("Microsoft.Security", "CA2116:AptcaMethodsShouldOnlyCallAptcaMethods", Justification = "Security handled by base class")]
        public AccordionDesigner()
        {
        }

        /// <summary>
        /// Initialize to make sure we're attached to an accordion control
        /// </summary>
        /// <param name="component">Component</param>
        [SuppressMessage("Microsoft.Globalization", "CA1303:DoNotPassLiteralsAsLocalizedParameters", Justification = "Assembly is not localized")]
        [SuppressMessage("Microsoft.Security", "CA2116:AptcaMethodsShouldOnlyCallAptcaMethods", Justification = "Security handled by base class")]
        public override void Initialize(IComponent component)
        {
            _accordion = component as Accordion;
            if (_accordion == null)
                throw new ArgumentException("Component must be an Accordion control", "component");
            base.Initialize(component);
        }

        /// <summary>
        /// Get the HTML for the Accordion
        /// </summary>
        /// <returns>HTML design time representation</returns>
        [SuppressMessage("Microsoft.Performance", "CA1804:RemoveUnusedLocals", MessageId = "controls", Justification = "See code comment below")]
        [SuppressMessage("Microsoft.Security", "CA2116:AptcaMethodsShouldOnlyCallAptcaMethods", Justification = "Security handled by base class")]
        public override string GetDesignTimeHtml()
        {
            // Ensure the controls have been created
            ControlCollection controls = _accordion.Controls;

            // Get the base html for the accordion's div
            // so that any accordion styles will be applied
            StringBuilder html = new StringBuilder();
            html.Append(base.GetDesignTimeHtml());

            // Remove the closing div tag so we can insert the HTML
            // for all of the panes
            html.Remove(html.Length - 6, 6);

            // Add the HTMl for each pane
            foreach (AccordionPane pane in _accordion.Panes)
            {
                html.Append("<span>");
                string headerCSS = !string.IsNullOrEmpty(pane.HeaderCssClass) ? pane.HeaderCssClass : _accordion.HeaderCssClass;
                html.AppendFormat("<div class=\"{0}\">", headerCSS);
                TemplateBuilder builder = pane.Header as TemplateBuilder;
                if (builder != null)
                    html.Append(builder.Text);
                html.Append("</div>");

                string contentCSS = !string.IsNullOrEmpty(pane.ContentCssClass) ? pane.ContentCssClass : _accordion.ContentCssClass;
                html.AppendFormat("<div class=\"{0}\">", contentCSS);
                builder = pane.Content as TemplateBuilder;
                if (builder != null)
                    html.Append(builder.Text);
                html.Append("</div>");
                html.Append("</span>");
            }

            html.Append("</div>");
            return html.ToString();
        }
    }
}

posted @ 2009-02-21 11:28  南守拥  阅读(532)  评论(0编辑  收藏  举报