EditorPartChrome 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
使开发人员能够仅覆盖区域中EditorPart所选控件部分的EditorZoneBase呈现。
public ref class EditorPartChrome
public class EditorPartChrome
type EditorPartChrome = class
Public Class EditorPartChrome
- 继承
-
EditorPartChrome
示例
下面的代码示例演示如何使用EditorPartChrome类替代区域中控件EditorPart的默认呈现EditorZoneBase。
该代码示例包含三个部分:
允许用户在 Web 部件页上更改显示模式的用户控件。
承载示例中所有控件的网页。
包含自定义 EditorPartChrome 类和 EditorZoneBase 区域的源代码的类。
代码示例的第一部分是用户控件。 用户控件的源代码来自另一个主题。 若要使此代码示例正常工作,需要从 “演练:更改 Web 部件页主题上的显示模式 ”中获取用户控件的 .ascx 文件,并将该文件放置在与本代码示例中的.aspx页相同的文件夹中。
示例的第二部分是网页。 请注意,文件顶部附近有一个 Register 指令来注册已编译的组件和标记前缀。 另请注意,页面使用元素 <aspSample:MyEditorZone>引用自定义编辑器区域。
<%@ 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:MyEditorZone ID="EditorZone1" runat="server">
<ZoneTemplate>
<asp:AppearanceEditorPart ID="AppearanceEditorPart1"
runat="server" />
<asp:LayoutEditorPart ID="LayoutEditorPart1"
runat="server" />
</ZoneTemplate>
</aspSample:MyEditorZone>
</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:MyEditorZone ID="EditorZone1" runat="server">
<ZoneTemplate>
<asp:AppearanceEditorPart ID="AppearanceEditorPart1"
runat="server" />
<asp:LayoutEditorPart ID="LayoutEditorPart1"
runat="server" />
</ZoneTemplate>
</aspSample:MyEditorZone>
</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>
该示例的第三部分包含自定义编辑器部件部件部件版式和编辑器部件区域的实现。
MyEditorZone
EditorZone扩展和重写CreateEditorPartChrome以返回自定义编辑器部件部件版式。
MyEditorPartChrome 更改方法中 CreateEditorPartChromeStyle 编辑器部件控件的背景色。 区域中的背景色在方法中 PerformPreRender 更改,文本将添加到方法中的 RenderPartContents 编辑器部件。
namespace Samples.AspNet.CS.Controls
{
[AspNetHostingPermission(SecurityAction.Demand,
Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand,
Level = AspNetHostingPermissionLevel.Minimal)]
public class MyEditorPartChrome : EditorPartChrome
{
public MyEditorPartChrome(EditorZoneBase zone)
: base(zone)
{
}
protected override Style CreateEditorPartChromeStyle(EditorPart editorPart, PartChromeType chromeType)
{
Style editorStyle = base.CreateEditorPartChromeStyle(editorPart, chromeType);
editorStyle.BackColor = Color.Bisque;
return editorStyle;
}
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, EditorPart editorPart)
{
writer.AddStyleAttribute("color", "red");
writer.RenderBeginTag("p");
writer.Write("Apply all changes");
writer.RenderEndTag();
editorPart.RenderControl(writer);
}
public override void RenderEditorPart(HtmlTextWriter writer, EditorPart editorPart)
{
base.RenderEditorPart(writer, editorPart);
}
}
[AspNetHostingPermission(SecurityAction.Demand,
Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand,
Level = AspNetHostingPermissionLevel.Minimal)]
public class MyEditorZone : EditorZone
{
protected override EditorPartChrome CreateEditorPartChrome()
{
return new MyEditorPartChrome(this);
}
}
}
Namespace Samples.AspNet.VB.Controls
<AspNetHostingPermission(SecurityAction.Demand, _
Level:=AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermission(SecurityAction.InheritanceDemand, _
Level:=AspNetHostingPermissionLevel.Minimal)> _
Public Class MyEditorPartChrome
Inherits EditorPartChrome
Public Sub New(ByVal zone As EditorZoneBase)
MyBase.New(zone)
End Sub
Protected Overrides Function CreateEditorPartChromeStyle(ByVal editorPart As System.Web.UI.WebControls.WebParts.EditorPart, ByVal chromeType As System.Web.UI.WebControls.WebParts.PartChromeType) As System.Web.UI.WebControls.Style
Dim editorStyle As Style
editorStyle = MyBase.CreateEditorPartChromeStyle(editorPart, 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 editorPart As System.Web.UI.WebControls.WebParts.EditorPart)
writer.AddStyleAttribute("color", "red")
writer.RenderBeginTag("p")
writer.Write("Apply all changes")
writer.RenderEndTag()
editorPart.RenderControl(writer)
End Sub
Public Overrides Sub RenderEditorPart(ByVal writer As System.Web.UI.HtmlTextWriter, ByVal editorPart As System.Web.UI.WebControls.WebParts.EditorPart)
MyBase.RenderEditorPart(writer, editorPart)
End Sub
End Class
<AspNetHostingPermission(SecurityAction.Demand, _
Level:=AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermission(SecurityAction.InheritanceDemand, _
Level:=AspNetHostingPermissionLevel.Minimal)> _
Public Class MyEditorZone
Inherits EditorZone
Protected Overrides Function CreateEditorPartChrome() As System.Web.UI.WebControls.WebParts.EditorPartChrome
Return New MyEditorPartChrome(Me)
End Function
End Class
End Namespace
注解
Chrome 是指外围用户界面(UI)元素,这些元素可框架区域中包含的每个 Web 部件控件或服务器控件。 控件的部件版式包括其边框、标题栏以及标题栏中显示的图标、标题文本和谓词菜单。 部件版式的外观在区域级别设置,并应用于该区域中的所有控件。
Web 部件控件集使用 EditorPartChrome 类来呈现控件的 EditorPart 部件版式。 此外,此类为开发人员提供了一种方法来自定义区域中任何 EditorPart 控件 EditorZoneBase 的呈现。 例如,可以重写 CreateEditorPartChromeStyle 该方法以自定义区域中 EditorZoneBase 定义的一些特定样式属性。
类 EditorPartChrome 包含几个重要方法,当你想要重写控件的 EditorPart 呈现时,这些方法非常有用。 一个是 EditorPartChrome 构造函数,在重写 CreateEditorPartChrome 自定义 EditorZoneBase 类中的方法以创建自定义 EditorPartChrome 对象的实例时使用。 另一个有用的方法是该方法 RenderPartContents ,可用于控制区域中控件内容区域的呈现(与页眉、页脚和标题栏等部件元素相反)。 最后,如果要对呈现 EditorPart 控件的所有方面进行完整的编程控制,则可以重写该方法 RenderEditorPart 。
继承者说明
如果继承自 EditorPartChrome 该类,则必须创建自定义 EditorZone 区域才能返回自定义 EditorPartChrome 类。 此类概述的示例部分演示如何创建自定义 EditorZone 区域以返回自定义 EditorPartChrome 类
构造函数
| 名称 | 说明 |
|---|---|
| EditorPartChrome(EditorZoneBase) |
初始化 EditorPartChrome 类的新实例。 |
属性
| 名称 | 说明 |
|---|---|
| Zone |
获取对关联 EditorZoneBase 区域的引用。 |
方法
| 名称 | 说明 |
|---|---|
| CreateEditorPartChromeStyle(EditorPart, PartChromeType) |
创建样式对象,该对象为对象呈现EditorPart的每个EditorPartChrome控件提供样式属性。 |
| Equals(Object) |
确定指定的对象是否等于当前对象。 (继承自 Object) |
| GetHashCode() |
用作默认哈希函数。 (继承自 Object) |
| GetType() |
获取当前实例的 Type。 (继承自 Object) |
| MemberwiseClone() |
创建当前 Object的浅表副本。 (继承自 Object) |
| PerformPreRender() |
执行在呈现 EditorPart 控件之前必须完成的任务。 |
| RenderEditorPart(HtmlTextWriter, EditorPart) |
呈现包含其所有部分的完整 EditorPart 控件。 |
| RenderPartContents(HtmlTextWriter, EditorPart) |
呈现控件的主要内容区域 EditorPart ,不包括页眉和页脚。 |
| ToString() |
返回一个表示当前对象的字符串。 (继承自 Object) |