Design of Workspaces
| Retired Content |
|---|
This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. |
Workspaces are components that encapsulate a particular visual way of displaying controls and SmartParts. The Composite UI Application Block includes the following types of workspaces:
- WindowWorkspace
- MdiWorkspace
- TabWorkspace
- DeckWorkspace
- ZoneWorkspace
You can use these workspaces within your Windows user interface applications or, if you prefer to use richer display method, you can build your own custom workspaces. A shell developer building workspaces can use them to enforce a common styling, look and feel, placement constraints, and activation options. For more information about creating your own workspaces, see Building Custom Workspaces.
Showing controls through workspaces allows you to consistently display, hide, activate, and monitor the parts shown, independently of the visual style in which they display. This allows the "look and feel" and layout of your shell to evolve independently of the SmartParts hosted within it.
Workspaces can show, hide, activate, or close a set of controls. In some situations, a workspace is based on a control; for example, the TabWorkspace is based on the TabControl. However, in other situations the workspace may have no underlying control, for example, the WindowWorkspace.
Workspaces can take hints that are used to define the control placement or look and feel of the application. For example, the WindowWorkspace takes hints on modality that are only relevant to that type of workspace. All workspaces should have a default behavior for use when no hints are available.
When developing your own workspaces, you may want to enable fine-grained control for the user to specify how the controls appear. To enable the consumer of a workspace to provide rich hinting and extra information, the workspace author can define a richer implementation of ISmartPartInfo that the SmartPart author can add to their controls. The SmartPartInfo class provides a default implementation of such an interface that supports drag & drop operation from the Visual Studio toolbox when used on the design surface with a SmartPart.
All workspaces implement the IWorkspace interface that includes the following members:
- Activate(Object smartPart). This method activates the SmartPart.
- Show(Object smartPart). This method displays the passed SmartPart.
- Show(Object smartPart, ISmartPartInfo smartPartInfo). This method displays the passed SmartPart providing hints in the SmartPartInfo for the concrete implementation to use.
- Hide(Object smartPart). This method hides the SmartPart.
- Close(Object smartPart). This method closes the SmartPart.
- object ActiveSmartPart(). This method returns the currently active SmartPart in the Workspace, if one exists.
- SmartParts. This property returns a collection of the SmartParts in this Workspace. You can use the collection to query for SmartParts that are contained in the Workspace.
- event EventHandler<WorkspaceCancelEventArgs> SmartPartClosing. This event is raised when a SmartPart is closing. The WorkspaceCancelEventArgs can be used to cancel the event.
- event EventHandler<WorkspaceEventArgs> SmartPartActivated. This event occurs on SmartPart activation. The WorkSpaceEventArgs provides access to the activated SmartPart.
The concrete workspaces implement different behaviors, as described in the following sections.
WindowWorkspace
The WindowWorkspace enables you to show and hide controls framed in a window. Its implementation of the IWorkspace methods can show, hide, and close a new window in which the SmartPart displays. The Show method can receive hints in an instance of the WindowSmartPartInfo component.
WindowSmartPartInfo
You can use the WindowSmartPartInfo component to specify that a SmartPart should be displayed modally. You add the component to your form, set its Modal property to true, and then pass this instance as the second parameter to the workspace Show method. The WindowSmartPartInfo component also provides the Title property, which you can use to set the Title property of the new form that is created.
MdiWorkspace
The MdiWorkspace enables you to show and hide controls and SmartParts in MDI child forms. It is based on the WindowWorkspace type and extends this to display the SmartParts as MDI child forms. Its implementation of the IWorkspace methods can show, hide, and close a new window in which the SmartPart displays. It receives the SmartPartInfo hint object in the Show method to set the title of the child form.
TabWorkspace
The TabWorkspace enables you to show and hide controls and SmartParts inside a tabbed page. Its implementation of the IWorkspace methods can show, hide, and close tabs in which the SmartPart displays. It receives the show hints through the basic SmartPartInfo component.
TabSmartPartInfo
You can use the TabSmartPartInfo component to specify whether the tab page where the SmartPart will be shown should be activated (the ActivateTab property), as well as its location related to other tabs (the Position property). This component inherits from the generic SmartPartInfo class, whose Title property determines the text on the tab for this page.
DeckWorkspace
The DeckWorkspace enables you to show and hide controls and SmartParts in an overlapped manner with no visible frame. Its implementation of the IWorkspace methods can show, hide, and close the SmartParts in a fashion similar to a deck of cards. Showing a SmartPart causes it to display on top of the previous SmartPart. Hiding a SmartPart displays the next top most SmartPart in the deck. Closing a SmartPart removes it from the deck and displays the next top most SmartPart. The workspace remembers the order in which the SmartParts are shown, hidden, and closed.
The DeckWorkspace does not use any additional hints to control how it displays the SmartParts. However, it does still provide the overload of the Show method, but ignores any SmartPartInfo component passed to it.
ZoneWorkspace
The ZoneWorkspace enables you to create a tiled workspace layout. For example, you can create an Outlook-style user interface with a navigation zone on the left and two horizontal zones on the right by using multiple splitter controls. Each content area where you can show a SmartPart can have a ZoneName specified through a property provided by the containing workspace on all its container controls, such as a Panel, FlowLayoutPanel, or the panels of a SplitContainer. You can then add SmartParts to the zone at design time or run time by accessing the zone by name using the ZoneWorkspace instance. Child container controls also have an IsDefaultZone property that can be set to true to identify one of the container controls as the default zone for displaying SmartParts in. The ZoneWorkspace receives information about how a SmartPart should appear ("show hints") through the ZoneSmartPartInfo component.
ZoneSmartPartInfo
You can use the ZoneSmartPartInfo component to specify the zone that a SmartPart should be displayed in. You add the component to your form, set its ZoneName property to name of zone that you want to display SmartParts in, and then pass this instance as the second parameter to the workspace Show method.
SmartPartInfo
You can use the generic SmartPartInfo component to specify the Title and Description for a SmartPart. A Workspace may be able to use this information if more specific information is not provided, for example to set the text on the tab of a TabWorkspace page.
Design Time Experience with SmartPartInfo Components
All built-in SmartPart information (SmartPartInfo) components support use in the Visual Studio toolbox, and you can drag and drop them onto forms and user controls in design view. A SmartPart may also support rich display hinting information for a range of potential hosting workspaces and other designer surfaces. By explicitly creating different kinds of SmartPartInfo class derivations to match the workspaces you plan to support for your SmartPart, you enable drag & drop onto different types of the design surface.
When you drag and drop the built-in SmartPartInfo components onto a SmartPart designer surface, code that passes this information to the Workspace showing the SmartPart is automatically added to your control. The code added that is added looks like the following.
public ISmartPartInfo GetSmartPartInfo(Type smartPartInfoType) { // the containing smart part must add ISmartPartInfo to the // interfaces it implements for the contained SmartPartInfos to work Microsoft.Practices.CompositeUI.SmartParts.ISmartPartInfoProvider ensureProvider = this; return this.infoProvider.GetSmartPartInfo(smartPartInfoType); }
By using an implicit cast, the first line of code forces you to add the ISmartPartInfoProvider interface to your class definition in order for the code to compile. This interface is required in order for the SmartPart to provide display its hinting information Workspace. In C#, you only need to add the ISmartPartInfoProvider to your class definition, as shown in the following code.
using Microsoft.Practices.CompositeUI.SmartParts; public class MySmartPart : UserControl, ISmartPartInfoProvider ...
For Visual Basic .NET, you also need to add the corresponding Implements keyword to the method signature.
Imports Microsoft.Practices.CompositeUI.SmartParts
Public Class MySmartPart
Implements ISmartPartInfoProvider
Public Function GetSmartPartInfo(ByVal smartPartInfoType As System.Type) _
As Microsoft.Practices.CompositeUI.SmartParts.ISmartPartInfo _
Implements ISmartPartInfoProvider.GetSmartPartInfo
...
These changes only need to be performed when the first SmartPartInfo is dropped onto the design surface.
The SmartPartInfoProvider component (in the field named infoProvider) that is automatically added takes care of providing the SmartPartInfo instances to the Workspaces as and when required. Note that this component is not visible in the design surface because it is not intended for use directly.