Customizing the Property Task Pane

Members can change a web part by clicking the web part's down arrow and selecting Modify Shared Web Part or Modify Personal Web Part. That action displays the property task pane. You can customize a web part's property task pane by overriding the GetToolParts method. For example, the following code hides the built-in AllowMinimize property and expands the Custom section of the property task pane, as shown in Figure 9-14.

     Public Overrides Function GetToolParts() As ToolPart()
         Dim toolParts(2) As ToolPart
         Dim wptp As WebPartToolPart = New WebPartToolPart
         Dim custom As CustomPropertyToolPart = New CustomPropertyToolPart
         ' Hide one of the built-in properties
         wptp.Hide(wptp.Properties.AllowMinimize)
         ' Expand the Custom section.
         custom.Expand("Custom")
         toolParts(0) = wptp
         toolParts(1) = custom
         Return toolParts
     End Function

The wptp object defined in the preceding code represents the toolpart for the built-in properties—those properties inherited from the WebPart base class. The custom object represents the toolpart for all the properties you defined for the web part.

SharePoint generates the controls displayed in the CustomPropertyToolPart class, based on the data type of the custom property and whether or not it is marked as

Customizing a web part's property task pane

Figure 9-14. Customizing a web part's property task pane

Browsable in the property attributes. Table 9-4 lists the controls generated ...

Get Essential SharePoint now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.