Loading...

All project content is available for reading, but you need to be a member of the project for Subversion checkout of source code, or to create/modify any information.
Login if you are a member. Apply here to request membership (open to all).

Custom handlers

PageTreeIcons was created with an extensible architecture to make it easy to add more ways to select when a page should display an icon. Basically all you have to do to create your own handler is follow two simple steps:

1. Implement the ITreeIconHandler interface

The first thing you need to do is create a class that implements the simple interface PageTreeIcons.ITreeIconHandler. The interface consists of two methods:

  • Initialize(NameValueCollection) - Called when the handler first is created. The NameValueCollection parameter holds all values from the mappings configuration element in web.config (See next section)
  • GetIcon(PageData) :: Image - Called for each page that is displayed in the page tree. Should return an icon image control if the page is a match to the mapping. Otherwise just return null.

To make it even easier PageTreeIcons comes with an abstract base class (PageTreeIcons.TreeIconHandlerBase) that provides some standard plumbing for you. It implements Initialize to extract the Icon and Tooltip values. It also implements GetIcon and instead lets you specify the IsMatch method that just return if the page is a match to your mapping.

For an example on how to implement ITreeIconHandler see the IconPropertyHandler from the online source. For an example on how to use TreeIconHandlerBase, see the source code of PageReferenceHandler.

2. Add your handler to the Web.Config

Add your handler to your configuration under the <handlers> section and specify you icon mapping configuration in the <mappings> section. Add your custom mapping attributes to the mapping element. Like this:

<pageTreeIcons>
  <handlers>
    <add name="MyCustomHandler" type="MyCompany.MyCustomHandler,MyAssembly" />
  </handlers>
  <mappings>
      <add key="Custom" handler="MyCustomHandler" customAttribute="CustomSelectionValue" />
  </mappings>
</pageTreeIcons>

For more detailed information, check out the configuration page.