This project has moved. For the latest updates, please go here.

UIElementCreationService

1. Description

The UIElementCreationService is used to create UI elements which can be added to UIExtensionSites. It helps to decouple the modules from the UI technology used by the Shell.

2. Motivation

The modules need to extend the user interface of the Shell. By example they need to add a new menu item which activates a use case. The Composite UI Application Block provides the UIExtensionSites for this requirement. The UIExtensionSites are UI independent and thus they support the principle of information hiding. A module should not care about which concrete UI elements are used in the Shell. An advantage of this concept is that the Shell can replace its concrete UI elements without affecting the modules (e.g. The MenuStrip of the shell is replaced with a more powerful third party menu control).

Listing 1 shows a module which adds a new menu item to the "ViewMenuItem" UIExtensionSite. The problem here is that this module is responsible to create the concrete ToolStripMenuItem instance. Therefore the module is not decoupled of the UI technology used by the shell. If the Shell is going to change the MenuStrip with another UI control this module needs to be changed too.

public override void Run()
{
    ToolStripMenuItem menuItem = new ToolStripMenuItem(
        "Visualizer", Resources.SignalVisualizer.ToBitmap());
    WorkItem.UIExtensionSites[UIExtensionSiteNames.ViewMenuItem].Add(menuItem);
    ...

Listing 1

3. Solution

To overcome this problem the Infrastructure.Module provides the UIElementCreationService. The module can delegate the creation of the concrete UI elements to this service. The implementation shown in Listing 2 is completely decoupled of the UI technology used by the Shell.

[ServiceDependency]
public IUIElementCreationService UIElementCreationService
{
    set { uiElementCreationService = value; }
}

public override void Run()
{
    IMenuItem menuItem = uiElementCreationService.CreateMenuItem(
            "Visualizer", Resources.SignalVisualizer.ToBitmap());
    WorkItem.UIExtensionSites[UIExtensionSiteNames.ViewMenuItem].Add(menuItem);
    ...

Listing 2

Last edited Oct 5, 2007 at 7:33 AM by jbe2277, version 4

Comments

No comments yet.