This article assumes that you are familiar with CAB (Composite UI Application Block), SCSF (Smart Client Software Factory), Guidance Packages and WPF (Windows Presentation Foundation). Although Microsoft Patterns & Practices team planned to provide support for WPF in April 2007 SCSF releases, this article demonstrates how to develop CAB workspaces that can use any technologies WITHOUT ANY WRAPPER WINDOWS.
Some community sites offer entire CAB in WPF technologies. But I would not recommend using those patterns since those do not comply with any standards. Also, CAB foundation must provide support for smart clients developed in .NET Framework 2.0 as well.
As you know, CAB is best known for its loosely coupled architectures, so why don't you architect your smart client also to couple loosely with WPF Windows & controls in CAB 2.0 environment?
CAB provides numerous patterns such as WorkItems, Workspaces, Controllers, Services, Commands, Actions, Event Broker, Modules, Dynamic Module Loader, Smart Parts, MVP, MVC patterns, Guidance Automations, Builder strategies, Profile Catalog, Smart web references, Entity translators, Layout principles and Shell. Among these patterns, Workspaces pattern is taken by this article.
During the Smart client UI design, Workspaces is the important pattern. This article is going to walkthrough how to design an XAML based window workspace using WPF or other technologies. In this loosely coupled architecture, Workspaces is a collection maintained in the
WorkItem object. You can create the workspace anywhere and use it anywhere.
There are two types of workspaces. Composable and Non-Composable. Composable workspaces are combined with some controls for example tab controls. Non-Composables are not combined with such controls.
Every workspace in CAB should be derived from
IWorkspace class found in
public abstract class Workspace<TSmartPart, TSmartPartInfo> : IWorkspace
abstract class designed in an excellent way that we can implement any types since it provides Generic types. (Please try to understand "Generics" before you continue this article – if you do not know.)
So, while implementing workspaces, you can use any types depending upon your technology needs.
The default CAB provides 2.0 window workspace like this:
public class WindowWorkspace : Workspace<Control, WindowSmartPartInfo>
Control is a 2.0 Control and
WindowSmartpartInfo provides additional details to construct and shows the 2.0 window.
We are going to implement like this in order to provide WPF support:
public class XamlWindowWorkspace : Workspace<UIElement, XamlWindowSmartPartInfo>
UIElement is an equivalent to
Control in WPF and
XamlWindowSmartpartInfo provides additional information to construct the XAML based WPF Windows.
Interop with 2.0 Shell
if (info.Modal == true)
new WindowInteropHelper(window).Owner = ownerForm.Handle;
During the API call
ShowDialog(), we need to attach the 2.0 shell window handle to WPF window. In order to do this, we need to use the
WindowInteropHelper class to get 3.0 window handle. Please note that, here we are just getting a handle of the XAML window. We are not using any wrapper windows to host XAML windows on 2.0 Windows.
XAML Window Attributes
To apply the additional XAML window attributes during the WPF windows launch the
XamlWindowSmartPartInfo class can be used. It provides the window attributes such as Modal flag, Startup location, Window state, Window style, Width, Height, Top most flag, etc.
You need to declare a new workspace constant in Infrastructure.Interface\Constants\WorkspaceNames.cs in order to use other modules as below.
public const string XamlWindowWorkspace = "XamlWindowWorkspace";
This XAML window workspace needs to be created along with the other default workspaces and added into workspaces collections as below:
XamlWindowWorkspace xamlWindowWsp = new XamlWindowWorkspace(_shellLayout.ParentForm);
The following sample demonstrates how to use this workspace:
IWorkspace wsp = this._presenter.WorkItem.Workspaces.Get("XamlWindowWorkspace");
Forms30View forms30View = this._presenter.WorkItem.SmartParts.AddNew<Forms30View>();
XamlWindowSmartPartInfo smartPartInfo = new XamlWindowSmartPartInfo();
smartPartInfo.Modal = true;
smartPartInfo.Title = " I am 3.0 Xaml Modal Window & View";
Guidance Package Changes
During the guidance package design, make the following changes in order to use this workspace by developers in addition to the default Microsoft's guidance package.
Two new files need to be added as below:
Changes are in:
Do not implement the entire CAB in 3.0 as its architecture itself provides a way to plug your workspaces in a loosely coupled manner. Depending upon your business needs, implement the workspaces in any technologies as demonstrated in this article.
- 22nd March, 2007: Initial post