CustomPropertyToolPart class
代表預設工具組件工具窗格中顯示的網頁組件,實作一或多個自訂屬性 (除了WebPart基底類別所提供的內容)。
Inheritance hierarchy
System.Object
System.Web.UI.Control
System.Web.UI.WebControls.WebControl
System.Web.UI.WebControls.Panel
System.Web.UI.WebControls.WebParts.Part
System.Web.UI.WebControls.WebParts.EditorPart
Microsoft.SharePoint.WebPartPages.EditorPartAdapter
Microsoft.SharePoint.WebPartPages.ToolPart
Microsoft.SharePoint.WebPartPages.CustomPropertyToolPart
Namespace: Microsoft.SharePoint.WebPartPages
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Syntax
'宣告
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
Public NotInheritable Class CustomPropertyToolPart _
Inherits ToolPart
'用途
Dim instance As CustomPropertyToolPart
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public sealed class CustomPropertyToolPart : ToolPart
備註
自訂屬性會自動顯示CustomPropertyToolPart類別的執行個體使用預設的 [屬性] 窗格中,如果屬性是類型String、 Boolean、 Integer,或Enum。下表說明每個這些屬性類型CustomPropertyToolPart類別中 [屬性] 窗格中的顯示方式。
屬性類型 |
做為屬性窗格中顯示 |
---|---|
布林值 |
核取方塊 |
列舉 |
向下放下 |
Integer |
文字方塊。 |
字串 |
文字方塊。 |
DateTime |
文字方塊。 |
Examples
下列簡單的網頁組件範例示範如何使用WebPartToolPart類別和自訂的網頁組件屬性,在工具窗格中顯示的CustomPropertyToolPart類別。此範例會WebPart基底類別的GetToolParts方法覆寫以後面接著其自訂屬性,在工具窗格中顯示網頁組件的標準屬性,然後展開每個工具組件的特定區段,並隱藏特定的標準屬性。WebPartToolPart類別會自動顯示網頁組件的標準屬性,並CustomPropertyToolPart類別會自動顯示網頁組件的自訂屬性。
Imports System
Imports System.ComponentModel
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Xml.Serialization
Imports Microsoft.SharePoint
Imports Microsoft.SharePoint.Utilities
Imports Microsoft.SharePoint.WebPartPages
' A simple Web Part with a single custom Text property.
<DefaultProperty("Text"), ToolboxData("<{0}:WebPart1
runat=server></{0}:WebPart1>"),
XmlRoot(Namespace:="WebPartLibrary1")> _
Public Class WebPart1
Inherits Microsoft.SharePoint.WebPartPages.WebPart
Private Const _defaultText As String = ""
Dim _text As String = _defaultText
' The Web Part's single custom Text property.
<Browsable(True), Category("Miscellaneous"),
DefaultValue(_defaultText), WebPartStorage(Storage.Personal),
FriendlyName("Text"), Description("Text Property")> _
Property [Text]() As String
Get
Return _text
End Get
Set(ByVal Value As String)
_text = Value
End Set
End Property
' An overridden version of the GetToolParts() method of the WebPart base class.
' The WebPartToolPart automatically displays the Web Part's standard properties
' The CustomPropertyToolPart displays automatically displays
' the Web Part's custom properties
Public Overrides Function GetToolParts() As ToolPart()
Dim toolParts(2) As ToolPart
Dim custom As CustomPropertyToolPart = New CustomPropertyToolPart
custom.Expand("Miscellaneous")
Dim wptp As WebPartToolPart = New WebPartToolPart
With wptp
.Expand(WebPartToolPart.Categories.Appearance)
.Hide(WebPartToolPart.Properties.FrameState)
.Hide(WebPartToolPart.Properties.FrameType)
End With
toolParts(0) = custom
toolParts(1) = wptp
Return toolParts
End Function
' Renders the Web Part.
Protected Overrides Sub RenderWebPart(ByVal output
As System.Web.UI.HtmlTextWriter)
output.Write(SPEncode.HtmlEncode([Text]))
End Sub
End Class
using System;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.WebPartPages;
namespace WebPartLibrary1CS
{
[DefaultProperty("Text"),
ToolboxData("<{0}:WebPart1 runat=server></{0}:WebPart1>"),
XmlRoot(Namespace="WebPartLibrary1CS")]
public class WebPart1 : Microsoft.SharePoint.WebPartPages.WebPart
{
private const string defaultText = "";
private string text=defaultText;
[Browsable(true),Category("Miscellaneous"),
DefaultValue(defaultText),
WebPartStorage(Storage.Personal),
FriendlyName("Text"),Description("Text Property")]
public string Text
{
get
{
return text;
}
set
{
text = value;
}
}
public override ToolPart[] GetToolParts()
{
ToolPart[] toolparts = new ToolPart[2];
CustomPropertyToolPart custom = new CustomPropertyToolPart();
WebPartToolPart wptp = new WebPartToolPart();
wptp.Expand(WebPartToolPart.Categories.Appearance);
wptp.Hide(WebPartToolPart.Properties.FrameState);
wptp.Hide(WebPartToolPart.Properties.FrameType);
toolparts[0] = wptp;
toolparts[1] = custom;
return toolparts;
}
protected override void RenderWebPart(HtmlTextWriter output)
{
output.Write(SPEncode.HtmlEncode(Text));
}
}
}
Thread safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.