Skip to main content

Registering Custom Views

  • 3 minutes to read

The NavBar control owns the Views collection, which allows quick customizing of the NavBar control appearance. At design time, all Views are accessible via the Views page of the NavBar designer:

or via the published property View. The View property also allows assigning a View to the NavBar control at runtime. It specifies the index of the required View within the list of registered NavBar control Views.

You can use not only the predefined Views, but also create and use custom Views. This topic provides the basics of custom View creation.

Each View of the NavBar control has an associated painter class, descending from the TdxNavBarPainter class or one of its descendants. This painter class encapsulates a number of ViewInfo and painter classes implementing layout of the NavBar controls elements and their appearance. After the custom painter class is created, the corresponding View must be registered with a new unique ID and name.

Let us create a View, combining the Office1 and Office3 Views:

Notice, that the difference between the Office1 and Office3 Views is the link selection painting. We need to obtain the link selection bounds from the Office3 View and replace the selection painting with Office1 selection painting.

The painter class for our View will be inherited from the TdxNavBarOffice1Painter class. We need to override two protected class functions: SelectionPainterClass function returning a class, implementing the link selection painting, and LinkViewInfoClass function returning a class, containing the item link bounds.

unit dxNavBarMyOfficeView;
interface
uses
  Windows, Graphics, dxNavBar, dxNavBarBaseViews, dxNavBarStyles, dxNavBarViewsFact, dxNavBarGraphics, dxNavBarOfficeViews, dxNavBarExplorerViews; dxNavBarCustomPainters;
TdxNavBarMyPainter = class(TdxNavBarOffice1Painter)
protected
  //the following function returns the painter class for the link
  //selection
  class function SelectionPainterClass: TdxNavBarCustomSelectionPainterClass; override;
  //the following function returns the ViewInfo class for the item
  //link
  class function LinkViewInfoClass: TdxNavBarLinkViewInfoClass; override;
end;
TdxNavBarMyOfficeLinkViewInfo = class(TdxNavBarLinkViewInfo)
public
  //TdxNavBarMyOfficeLinkView class overrides the SelectionRect
  //function, returning the link selection bounds
  function SelectionRect: TRect; override;
end;
class function TdxNavBarMyPainter.SelectionPainterClass: TdxNavBarCustomSelectionPainterClass;
begin
  //the SelectionPainterClass function returns the
  // TdxNavBarBaseSelectionPainter class, implementing the link
  // selection painting in Office1 View
  Result := TdxNavBarBaseSelectionPainter;
end;
class function TdxNavBarMyPainter.LinkViewInfoClass: TdxNavBarLinkViewInfoClass;
begin
  //the LinkViewInfoClass function returns the ViewInfo class for
  //the item link
  Result := TdxNavBarMyOfficeLinkViewInfo;
end;
function TdxNavBarMyOfficeLinkViewInfo.SelectionRect: TRect;
begin
  //the following code returns the link selection bounds similar to
  //the Office1 View
  Result := Rect;
  InflateRect(Result, -1, -1);
end;
initialization
  //custom View is registered with 20 as ID value and MyOfficeView as
  //the name
  RegisterView(20, 'MyOfficeView', TdxNavBarMyPainter);
finalization
  //un-registers the MyOfficeView View using its ID
  UnRegisterView(20);
end.

If you want to register a View so that it can be available at design time, the name of the unit containing the View implementation must be added to:

  • the uses section in one of the design time package units (typically the dxNavBarReg unit);

  • the implementation uses section in one of the runtime package units (typically the dxNavBar unit).

The RegisterView method must be called within the initialization section of the unit that implements the View. To un-register the View, call the UnRegisterView method within the unit’s finalization section.