CatalogPartChrome 类

定义

允许开发人员仅重写 CatalogPart 区域中 CatalogZoneBase 控件的选定部分的呈现。

public ref class CatalogPartChrome
public class CatalogPartChrome
type CatalogPartChrome = class
Public Class CatalogPartChrome
继承
CatalogPartChrome

示例

下面的代码示例演示如何使用 CatalogPartChrome 类替代区域中控件CatalogZoneBase的默认呈现CatalogPart

该代码示例包含三个部分:

  • 一个用户控件,可用于更改 Web 部件页上的显示模式。

  • 承载示例中所有控件的网页。

  • 包含自定义 CatalogPartChrome 类和 CatalogZoneBase 区域的源代码的类。

代码示例的第一部分是用户控件。 用户控件的源代码来自另一个主题。 若要使此代码示例正常工作,需要从 演练:更改 Web 部件页上的显示模式 主题中获取用户控件的 .ascx 文件,并将文件放置在此代码示例中.aspx页所在的文件夹中。

该示例的第二部分是网页。 请注意,文件顶部附近有一个 Register 指令用于注册已编译的组件和标记前缀。 另请注意,该页使用 元素 <aspSample:MyCatalogZone>引用自定义目录区域。

<%@ Page Language="C#" %>
<%@ register tagprefix="aspSample" 
  Namespace="Samples.AspNet.CS.Controls" %>
<%@ Register TagPrefix="uc1" TagName="DisplayModeMenuCS" Src="~/DisplayModeMenuCS.ascx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
  <title>Web Parts Page</title>
</head>
<body>
  <h1>Web Parts Demonstration Page</h1>
  <form runat="server" id="form1">
<asp:webpartmanager id="WebPartManager1" runat="server" />
<uc1:DisplayModeMenuCS runat="server" ID="DisplayModeMenu" />
  <br />
  <table cellspacing="0" cellpadding="0" border="0">
    <tr>
      <td valign="top">
    <asp:webpartzone id="SideBarZone" runat="server" 
        headertext="Sidebar">
        <zonetemplate>
        </zonetemplate>
      </asp:webpartzone>
      <aspSample:MyCatalogZone ID="CatalogZone1" runat="server">
      <ZoneTemplate>
          <asp:ImportCatalogPart ID="ImportCatalog" runat="server" />
      </ZoneTemplate>
    </aspSample:MyCatalogZone>
      </td>
      <td valign="top">
    <asp:webpartzone id="MainZone" runat="server" headertext="Main">
         <zonetemplate>
        <asp:label id="contentPart" runat="server" Title="Content">
              <h2>Welcome to My Home Page</h2>
              <p>Use links to visit my favorite sites!</p>
            </asp:label>
         </zonetemplate>
       </asp:webpartzone>
      </td>
      <td valign="top">
      </td>
    </tr>
  </table>
  </form>
</body>
</html>
<%@ Page Language="VB" %>
<%@ register tagprefix="aspSample" 
  Namespace="Samples.AspNet.VB.Controls" %>
<%@ Register TagPrefix="uc1" TagName="DisplayModeMenuVB" Src="~/DisplayModeMenuVB.ascx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
  <title>Web Parts Page</title>
</head>
<body>
  <h1>Web Parts Demonstration Page</h1>
  <form runat="server" id="form1">
<asp:webpartmanager id="WebPartManager1" runat="server" />
<uc1:DisplayModeMenuVB runat="server" ID="DisplayModeMenu" />
  <br />
  <table cellspacing="0" cellpadding="0" border="0">
    <tr>
      <td valign="top">
    <asp:webpartzone id="SideBarZone" runat="server" 
        headertext="Sidebar">
        <zonetemplate>
        </zonetemplate>
      </asp:webpartzone>
      <aspSample:MyCatalogZone ID="CatalogZone1" runat="server">
      <ZoneTemplate>
          <asp:ImportCatalogPart ID="ImportCatalog" runat="server" />
      </ZoneTemplate>
    </aspSample:MyCatalogZone>
      </td>
      <td valign="top">
    <asp:webpartzone id="MainZone" runat="server" headertext="Main">
         <zonetemplate>
        <asp:label id="contentPart" runat="server" Title="Content">
              <h2>Welcome to My Home Page</h2>
              <p>Use links to visit my favorite sites!</p>
            </asp:label>
         </zonetemplate>
       </asp:webpartzone>
      </td>
      <td valign="top">
      </td>
    </tr>
  </table>
  </form>
</body>
</html>

该示例的第三部分包含自定义目录部件部件部件和目录部件区域的实现。 MyCatalogZone 扩展 CatalogZone 和重写 CreateCatalogPartChrome 以返回自定义目录部件部件版式。 MyCatalogPartChrome 更改 方法中 CreateCatalogPartChromeStyle 目录控件的背景色。 区域的背景色在 方法中 PerformPreRender 更改,文本将添加到 方法中的 RenderPartContents 目录部件。

namespace Samples.AspNet.CS.Controls
{

    /// <summary>
    /// Summary description for source
    /// </summary>
    public class MyCatalogPartChrome : CatalogPartChrome
    {
        public MyCatalogPartChrome(CatalogZoneBase zone)
            : base(zone)
        {
        }

        protected override Style  CreateCatalogPartChromeStyle(CatalogPart catalogPart, PartChromeType chromeType)
        {
            Style catalogStyle = base.CreateCatalogPartChromeStyle(catalogPart, chromeType);
            catalogStyle.BackColor = Color.Bisque;
            return catalogStyle;
        }

        public override void PerformPreRender()
        {
            Style zoneStyle = new Style();
            zoneStyle.BackColor = Color.Cornsilk;

            Zone.Page.Header.StyleSheet.RegisterStyle(zoneStyle, null);
            Zone.MergeStyle(zoneStyle);
        }

        protected override void  RenderPartContents(HtmlTextWriter writer, CatalogPart catalogPart)
        {
            writer.AddStyleAttribute("color", "red");
            writer.RenderBeginTag("p");
            writer.Write("Apply all changes");
            writer.RenderEndTag();
            catalogPart.RenderControl(writer);
        }

        public override void  RenderCatalogPart(HtmlTextWriter writer, CatalogPart catalogPart)
        {
            base.RenderCatalogPart(writer, catalogPart);
        }
    }

    public class MyCatalogZone : CatalogZone
    {
        protected override CatalogPartChrome  CreateCatalogPartChrome()
        {
            return new MyCatalogPartChrome(this);
        }
    }
}
Namespace Samples.AspNet.VB.Controls


    Public Class MyCatalogPartChrome
        Inherits CatalogPartChrome

        Public Sub New(ByVal zone As CatalogZoneBase)
            MyBase.New(zone)
        End Sub

        Protected Overrides Function CreateCatalogPartChromeStyle(ByVal catalogPart As System.Web.UI.WebControls.WebParts.CatalogPart, ByVal chromeType As System.Web.UI.WebControls.WebParts.PartChromeType) As System.Web.UI.WebControls.Style
            Dim editorStyle As Style
            editorStyle = MyBase.CreateCatalogPartChromeStyle(catalogPart, chromeType)
            editorStyle.BackColor = Drawing.Color.Bisque
            Return editorStyle
        End Function

        Public Overrides Sub PerformPreRender()
            Dim zoneStyle As Style = New Style
            zoneStyle.BackColor = Drawing.Color.Cornsilk

            Zone.Page.Header.StyleSheet.RegisterStyle(zoneStyle, Nothing)
            Zone.MergeStyle(zoneStyle)
        End Sub

        Protected Overrides Sub RenderPartContents(ByVal writer As System.Web.UI.HtmlTextWriter, ByVal catalogPart As System.Web.UI.WebControls.WebParts.CatalogPart)
            writer.AddStyleAttribute("color", "red")
            writer.RenderBeginTag("p")
            writer.Write("Apply all changes")
            writer.RenderEndTag()
            catalogPart.RenderControl(writer)
        End Sub

        Public Overrides Sub RenderCatalogPart(ByVal writer As System.Web.UI.HtmlTextWriter, ByVal catalogPart As System.Web.UI.WebControls.WebParts.CatalogPart)
            MyBase.RenderCatalogPart(writer, catalogPart)
        End Sub
    End Class

    Public Class MyCatalogZone
        Inherits CatalogZone

        Protected Overrides Function CreateCatalogPartChrome() As System.Web.UI.WebControls.WebParts.CatalogPartChrome
            Return New MyCatalogPartChrome(Me)
        End Function
    End Class
End Namespace

注解

Chrome 是指外围用户界面 (UI) 元素,这些元素构成区域中包含的每个 Web 部件控件或服务器控件的框架。 控件的版式包括其边框、标题栏以及标题栏中显示的图标、标题文本和谓词菜单。 Chrome 的外观在区域级别设置,并应用于区域中的所有控件。

Web 部件控件集使用 CatalogPartChrome 类来呈现控件的 CatalogPart 版式。 此外,此类为开发人员提供了一种自定义区域中任何 CatalogPart 控件 CatalogZoneBase 呈现的方法。 例如,可以重写 方法, CreateCatalogPartChromeStyle 以自定义应用于 CatalogZoneBase 区域的某些特定样式属性。

CatalogPartChrome 包含几个重要方法,在想要替代控件的 CatalogPart 呈现时,这些方法非常有用。 一个是CatalogPartChrome构造函数,在自定义CatalogZoneBase区域中重写 CreateCatalogPartChrome 方法以创建自定义对象的实例CatalogPartChrome时使用该构造函数。 另一种有用的方法是 RenderPartContents 方法,可用于控制区域 (中控件的内容区域的呈现,而不是页眉、页脚和标题栏等 chrome 元素) 。 最后,如果希望对呈现控件的所有方面进行完全编程控制 CatalogPart ,可以重写 RenderCatalogPart 方法。

继承者说明

如果从 CatalogPartChrome 类继承,则必须创建自定义 CatalogZone 区域才能返回自定义 CatalogPartChrome 类。 此类概述的示例部分演示如何创建自定义 CatalogZone 区域以返回自定义 CatalogPartChrome 类。

构造函数

CatalogPartChrome(CatalogZoneBase)

初始化 CatalogPartChrome 类的新实例。

属性

Zone

获取对关联的 CatalogZoneBase 区域的引用。

方法

CreateCatalogPartChromeStyle(CatalogPart, PartChromeType)

创建样式对象,该对象为 CatalogPart 对象呈现的每个 CatalogPartChrome 控件提供样式特性。

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
PerformPreRender()

执行在呈现 CatalogPart 控件之前必须完成的任务。

RenderCatalogPart(HtmlTextWriter, CatalogPart)

呈现完整的 CatalogPart 控件及其所有部分。

RenderPartContents(HtmlTextWriter, CatalogPart)

呈现 CatalogPart 控件的主要内容区域,不包括页眉和页脚。

ToString()

返回表示当前对象的字符串。

(继承自 Object)

适用于

另请参阅