Click here to Skip to main content
Licence CPOL
First Posted 22 Mar 2007
Views 40,997
Downloads 177
Bookmarked 21 times

Launch XAML Windows in CAB 2.0

Design XAML workspaces in CAB

Introduction

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 Workspaces

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 Workspace/IWorkspace class found in CompositeUI.SmartParts namespace.

public abstract class Workspace<TSmartPart, TSmartPartInfo> : IWorkspace 

This 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> 

where 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> 

where 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)
{
SetWindowLocation(window, info);
//Set parent form, Handle can be null
new WindowInteropHelper(window).Owner = ownerForm.Handle;
// Show dialog.
window.ShowDialog();
} 

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.

Workspace Constant

You need to declare a new workspace constant in Infrastructure.Interface\Constants\WorkspaceNames.cs in order to use other modules as below.

//Newly Added 
public const string XamlWindowWorkspace = "XamlWindowWorkspace"; 

Workspace Creation

This XAML window workspace needs to be created along with the other default workspaces and added into workspaces collections as below:

// Add XAML window workspace to be used for launching XAML based modal 
// or modeless windows 
XamlWindowWorkspace xamlWindowWsp = new XamlWindowWorkspace(_shellLayout.ParentForm); 
_rootWorkItem.Workspaces.Add(xamlWindowWsp, WorkspaceNames.XamlWindowWorkspace);

Sample Usage

The following sample demonstrates how to use this workspace:

//Get 3.0 modal workspace from Root WorkItem 
IWorkspace wsp = this._presenter.WorkItem.Workspaces.Get("XamlWindowWorkspace"); 

//Add a new 3.0 Smart part 
Forms30View forms30View = this._presenter.WorkItem.SmartParts.AddNew<Forms30View>(); 

//Create extra details to launch window 
XamlWindowSmartPartInfo smartPartInfo = new XamlWindowSmartPartInfo(); 
smartPartInfo.Modal = true; 
smartPartInfo.Title = " I am 3.0 Xaml Modal Window & View"; 

//Launch modal dialog 
wsp.Show(forms30View, smartPartInfo); 

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:

  • Infrastructure.Library\UI\XamlWindowWorkspace.cs
  • Infrastructure.Library\UI\XamlWindowSmartPartInfo.cs

Changes are in:

  • Infrastructure.Interface\Constants\WorkspaceNames.cs
  • Infrastructure.Layout\Module.cs

Conclusion

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.

History

  • 22nd March, 2007: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Venkatakarthikeyan Natarajamoorthy

Software Developer (Senior)

United States United States

Member

Venkat Nataraj works as a Technical Consultant for GE Healthcare, USA. Earlier, he worked as a Software Tech Lead for Dell Inc, System Analyst for Satyam Computer Services and Software Engineering Consultant for GE Power Systems, Bently Nevada. He is an MCSD.NET early achiever. He has been working in the last 11+ years in software design and development of leading-edge business solutions with various development tools, technologies, platforms, and architectures. Here is the latest certifications by him:
 
• General Electric (GE) Certified GE Green Belt in Six Sigma
• Microsoft Certified Professional (MCP)
• Microsoft Certified Application Developer for Microsoft .NET (MCAD.NET)
• Microsoft Certified Solution Developer for Microsoft .NET (MCSD.NET)
• MCSD.NET Early achiever
• Brainbench Certified Visual C++ programmer
• Computer Society of India (CSI) awarded first place in the inter-college Computer Quiz Competition
• Computer Society of India (CSI) awarded first place in the inter-college Software Contest
• Received “Process Innovation” award from Dell Inc
 
He spends his free time with music, watching hollywood movies and Sujatha's stories. His favorite musician is Ilayaraja. Bringing real music to his soul and heart. Hariharan is his most favorite singer.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralView not disposed when window is closed ! Pinmemberrjknis23:58 29 Apr '08  
GeneralRe: View not disposed when window is closed ! PinmemberEthan_S1:52 11 Oct '08  
GeneralError while adding WindowWorkspace class in Interface.Library.UI Pinmemberseresha1:56 6 Jul '07  

Thats a nice discussion with Kent. Infact I started my work on SCSF applications using Kent's Bank Teller. But still making some changes to my application based on requirements that I came across this article.
 
I do have an issue when I tried to implement the code of XAMLWindowWorkspace. Do let me know where I need to make changes..
 
1. The type 'Microsoft.Practices.CompositeUI.SmartParts.Workspace`2<T0,T1>' is defined in an assembly that is not referenced. You must add a reference to assembly 'Microsoft.Practices.CompositeUI, Version=1.0.51205.0, Culture=neutral, PublicKeyToken=null'.     D:\Projects\MyApplication\Source\Infrastructure\Infrastructure.Library\UI\WindowWorkspace.cs     23     18     Infrastructure.Library
 
2. The type 'Microsoft.Practices.CompositeUI.SmartParts.SmartPartInfo' is defined in an assembly that is not referenced. You must add a reference to assembly 'Microsoft.Practices.CompositeUI, Version=1.0.51205.0, Culture=neutral, PublicKeyToken=null'.     D:\Projects\MyApplication\Source\Infrastructure\Infrastructure.Library\UI\WindowSmartpartInfo.cs     20     18     Infrastructure.Library
 
3.The type or namespace name 'UI' does not exist in the namespace 'Mobile.Infrastructure.Library' (are you missing an assembly reference?)     D:\Projects\MyApplication\Source\Infrastructure\Infrastructure.Layout\Module.cs     5     37     Infrastructure.Layout
 

I am surprised of Version number (51205) but all of the dll including of XAMLWindowWorkspace support 50727.
 
do let me know what could be the reason for each error and how can i troubleshoot it.
 
Is there any cross reference happened....
 
Thanks in advance..

GeneralRe: Error while adding WindowWorkspace class in Interface.Library.UI PinmemberVenkatakarthikeyan Natarajamoorthy11:40 6 Jul '07  
Generalbuild problem Pinmember!Bug13:45 7 Apr '07  
GeneralRe: build problem PinmemberVenkatakarthikeyan Natarajamoorthy15:59 7 Apr '07  
GeneralRe: build problem Pinmember!Bug13:57 8 Apr '07  
QuestionQuestions PinmemberKent Boogaart22:12 23 Mar '07  
AnswerRe: Questions PinmemberVenkatakarthikeyan Natarajamoorthy11:41 26 Mar '07  
GeneralRe: Questions PinmemberKent Boogaart15:15 26 Mar '07  
GeneralRe: Questions PinmemberVenkatakarthikeyan Natarajamoorthy4:15 28 Mar '07  
GeneralRe: Questions PinmemberDarrelMiller16:48 18 Apr '07  
GeneralRe: Questions PinmemberKent Boogaart1:40 2 May '07  
GeneralRe: Questions PinmemberVenkatakarthikeyan Natarajamoorthy11:44 6 Jul '07  
GeneralRe: Questions PinmemberKent Boogaart14:54 6 Jul '07  
GeneralInnovative Architectural Idea!!! Pinmembersivas_v15:04 22 Mar '07  
GeneralRe: Innovative Architectural Idea!!! PinmemberVenkatakarthikeyan Natarajamoorthy11:44 26 Mar '07  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120529.1 | Last Updated 22 Mar 2007
Article Copyright 2007 by Venkatakarthikeyan Natarajamoorthy
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid