HowTo: manage dynamic layouts using CAB

A common requirement for applications is change the layout of the Shell depending on certain conditions.

The best way to handle this scenario in CAB is having a DeckWorkspace on the Shell. Then, there might be different layouts implemented in terms of smartparts that might be shown under different conditions. Let's create a simple example. Think about two layouts: the CRM layout and the Transactions Layout. The proposed solution could be extended to as many layouts as the application needs.

First thing is the Shell. Here we have our Primary Workspace of type DeckWorkspace.


Having a DeckWorkspace will allow showing/hiding different layouts efficiently. This snippet of code shows how:

private void ShowLayout(){ WorkItem.Workspaces[WorkspaceNames.PrimaryWorkspace].Show(WorkItem.Items.Get("Layout"));}

Each layout is a single SmartPart

(UserControl). These layouts will hold a ZoneWorkspace. This type of workspace is well suited for UIs where multiple sources of information must be shown. It is similar to a Sharepoint webpage. Working with this workspace is a little tricky. You have to add Panels and assign those panels a ZoneName. Let's suppose we have the following layout for the CRM module:


The following code illustrates how to show different views within the ZoneWorkspace for this module.

And also, the same code applies to show a smartpart within the nested TabWorkspace in the same

layout. CAB is intelligent enough to detect that the Layout smartpart contains instances of IWorkspace and add it to the WorkItem container so we can use it later.

Finally, the next figure illustrates the layout for the Transactions module.


Let’s see some screenshot of this concept implemented with CAB and SC-BAT March CTP.



Download the sample solution from here

private void ShowCustomerActionsViews(){ TabSmartPartInfo info1 = new TabSmartPartInfo(); info1.Title = "Summary"; TabSmartPartInfo info2 = new TabSmartPartInfo(); info2.Title = "Tasks"; WorkItem.Workspaces[WorkspaceNames.CustomerActionsWorkspace].Show(WorkItem.Items.Get("CustomerSummary"), info1); WorkItem.Workspaces[WorkspaceNames.CustomerActionsWorkspace].Show(WorkItem.Items.Get("CustomerTasks"), info2);}  
private void ShowCustomerViews(){ ZoneSmartPartInfo info1 = new ZoneSmartPartInfo("CustomerNotes"); info1.Dock = DockStyle.Fill; ZoneSmartPartInfo info2 = new ZoneSmartPartInfo("CustomerInfo"); info2.Dock = DockStyle.Fill; WorkItem.Workspaces[WorkspaceNames.CrmLayoutWorkspace].Show(WorkItem.Items.Get("CustomerNotes"), info1); WorkItem.Workspaces[WorkspaceNames.CrmLayoutWorkspace].Show(WorkItem.Items.Get("CustomerInfo"), info2);}  

Published: March 29 2006

blog comments powered by Disqus