CatalogPartChrome クラス
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
開発者は、CatalogPart ゾーン内のCatalogZoneBase コントロールの選択したセクションに対してのみレンダリングをオーバーライドできます。
public ref class CatalogPartChrome
public class CatalogPartChrome
type CatalogPartChrome = class
Public Class CatalogPartChrome
- 継承
-
CatalogPartChrome
例
次のコード例では、CatalogPartChrome クラスを使用して、CatalogPart ゾーン内のCatalogZoneBase コントロールの既定のレンダリングをオーバーライドする方法を示します。
このコード例には、次の 3 つの部分があります。
Web パーツ ページの表示モードを変更できるユーザー コントロール。
この例のすべてのコントロールをホストする Web ページ。
カスタム CatalogPartChrome クラスと CatalogZoneBase ゾーンのソース コードを含むクラス。
コード例の最初の部分は、ユーザー コントロールです。 ユーザー コントロールのソース コードは、別のトピックから取得されます。 このコード例を機能させるには、「 チュートリアル: Web パーツ ページでの表示モードの変更 」トピックからユーザー コントロールの .ascx ファイルを取得し、このコード例の .aspx ページと同じフォルダーにファイルを配置する必要があります。
この例の 2 番目の部分は Web ページです。 コンパイル済みコンポーネントとタグ プレフィックスを登録するために、ファイルの先頭付近に 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>
この例の 3 番目の部分には、カスタム カタログ パーツクロムとカタログ パーツ ゾーンの実装が含まれています。
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 は、ゾーンに含まれる各 Web パーツ コントロールまたはサーバー コントロールをフレームに収める周辺機器ユーザー インターフェイス (UI) 要素を指します。 コントロールのクロムには、境界線、タイトル バー、およびタイトル バー内に表示されるアイコン、タイトル テキスト、動詞メニューが含まれます。 クロムの外観はゾーン レベルで設定され、ゾーン内のすべてのコントロールに適用されます。
Web パーツ コントロール セットは、 CatalogPartChrome クラスを使用して、 CatalogPart コントロールのクロムをレンダリングします。 さらに、このクラスは、開発者がCatalogPart ゾーン内の任意のCatalogZoneBase コントロールのレンダリングをカスタマイズする方法を提供します。 たとえば、 CreateCatalogPartChromeStyle メソッドをオーバーライドして、 CatalogZoneBase ゾーンに適用される特定のスタイル属性をカスタマイズできます。
CatalogPartChrome クラスには、CatalogPart コントロールのレンダリングをオーバーライドする場合に便利ないくつかの重要なメソッドが含まれています。 1 つは CatalogPartChrome コンストラクターです。カスタム CreateCatalogPartChrome ゾーンのCatalogZoneBase メソッドをオーバーライドして、カスタム CatalogPartChrome オブジェクトのインスタンスを作成するときに使用します。 もう 1 つの便利な方法は、 RenderPartContents メソッドです。これは、(ヘッダー、フッター、タイトル バーなどのクロム要素ではなく) ゾーン内のコントロールのコンテンツ領域のレンダリングを制御するために使用できます。 最後に、 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) |