Click here to Skip to main content
Licence CPOL
First Posted 22 Mar 2007
Views 41,001
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  
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  
Hi, Here are the answers for your questions:
 
1. I gone through your code today. Your code doe not comply with Microsoft's patterns & practices since it does supports ONLY WPF technologies. Please note that CAB patterns is a framework to develop smart clients to host any parts and NOT restricted to any technologies.
 
2. Lot more differences between your code and my code as below:
i) Your code does not support any controls other than WPF. But my code comply with Microsoft CAB standards and you can plug any controls in this framework. This sample demonstrate a XAML window workspace - how to plug.
ii) Your WindowWorkspace is hanging alone. Yes, your window workspace does not have any parent window (Or Desktop window is a parent). Please look at your method - GetOrCreateWindow(). You must provide Shell's handle as I explained in my article (without any wrapper window to gain performance). FYI - You can use tools like Spy++ to view the window hierarchy.
iii) CAB Workspace means - it supports collections of smart parts. In other way, it knows how to render more than one smart parts. Your WindowWorkspace does not support more than one smart part. That means your WindowWorkspace is not a workspace at all. It is just a window to show one control. Rather my code is a real CAB workspace and it provides support for more than one smart parts as like other workspaces
iv) You do not have any dispose logic while removing smart parts in the workspace's smart parts collections.
v) WindowSmartPartInfo class members are not having any default values. It is against to the CAB SmartPartInfo architecture.
 
The list may grow if someone else look at your sources.
 
3. If you look at the Microsoft CAB team's roadmap -
 
http://www.codeplex.com/smartclient[^]
http://blogs.msdn.com/blaine/[^]
 
Priority 1
WPF Interoperability
- Demonstrate how a Windows Forms Application can host Windows Presentation Foundation Parts
- Create a new View/Presenter recipe for WPF views

 
Unlike you stated at your community site, Microsoft's SCSF team is going to provide support for only to adopt the WPF/WF technologies in the form of recipes, guidance and interops. THEY ARE NOT GOING TO BUILD ENTIRE CAB IN WPF.
 
Are you going to write one more CAB to support WF? In future, every time do we need to write CAB for every .net's new release? Microsoft never re-implement CAB in WPF. Because CAB is not just a visual element hosting environment. Its more than that. It is a framework - it is a Design Patterns to adopt any technologies.
 
4. Have you seen Infragistics CAB libraries?
 
Please look at here: http://www.infragistics.com/hot/cab.aspx[^]
They built before you and their library is exactly like what you did. They re-implemented CompositeUI.Winforms project alone to plug their special controls into CAB envirorment. It does not means that they are not allowing any other controls.
 
5. Answer to your second question:
using the IWorkspace/Workspace interface generics parameters, you can write any workspaces that hosts any technology parts. You can see some sample customization by Microsoft at the folder: Infrastructure.Library/UI. You can customize or implement additional workspaces here based on your business needs. (FYI - You can also write workspaces using Active-X Controls, Win32 Controls or using any other technologies)
 
I am happy to answer if you have more questions!!!
 
Thanks, Venkat

 

 

 
Venkatakarthikeyan Natarajamoorhty

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