2. creating and loading the module
3. Adding the tabbed workspace to the form and running the module
4. Creating and adding the SmartPart user control to the module, and displaying the results through this SmartPart
Creating the Shell and the Form
1. Application name -> ShellApplication
2. Form1.cs -> ShellForm.cs
3. Add References
Microsoft.Practices.CompositeUI.dllAdding a new WorkItem
Microsoft.Practices.CompositeUI.WinForms.dll
Microsoft.Practices.ObjectBuilder.dll
4. Add New class named ShellWorkItem.cs
Using Microsoft.Practices.CompositeUI
5. Class should be public and inherit from WorkItem
public class ShellWorkItem : WorkItem6. Rename Program.cs to ShellApplication.cs
{
}
using Microsoft.Practices.CompositeUI.WinForms;7. Replace the static class with public and inherit from FormShellApplication
public class ShellApplication : FormShellApplication<ShellWorkItem, ShellForm>8. Add the [STAThread] attribute and intiate ShellApplication class and call Run method.
{
}
[STAThread]
static void Main()
{
new ShellApplication().Run();
}
Creating and Loading the Module
1. Create a new Class Library named MyModule
2. set Outputpath to ..\ShellApplication\bin\Debug (from project properties build output page)
3. Add reference
Microsoft.Practices.CompositeUI.dll4. Add a class named MyWorkItem.cs. Make it public and derive from WorkItem
Microsoft.Practices.CompositeUI.WinForms.dll
Microsoft.Practices.ObjectBuilder.dll
using Microsoft.Practices.CompositeUI;5. Add a class named MyModuleInit.cs and make it public and derive from ModuleInit. Add a variable myCatalogService reference the WorkItemTypeCatalogService. so that you can access it to register your WorkItem.
public class MyWorkItem : WorkItem
{
}
using Microsoft.Practices.CompositeUI;6. Add the following public property
using Microsoft.Practices.CompositeUI.Services;
using System.Windows.Forms;
public class MyModuleInit : ModuleInit
{
private IWorkItemTypeCatalogService myCatalogService;
}
[ServiceDependency]7. Override the Load method of ModuleInit
public IWorkItemTypeCatalogService myWorkItemCatalog
{
set { myCatalogService = value; }
}
public override void Load()8. Add a new XML file named ProfileCatalog.xml
{
base.Load();
myCatalogService.RegisterWorkItem<MyWorkItem>();
}
<?xml version="1.0" encoding="utf-8" ?>9. select property of ProfileCatalog.xml and change the Copy To Output Directory property to Copy Always
<SolutionProfile xmlns="http://schemas.microsoft.com/pag/cab-profile">
<Modules>
<ModuleInfo AssemblyFile="MyModule.dll" />
</Modules>
</SolutionProfile>
Adding the TabWorkspace
1. Open the ShellForm.cs and drag a SplitContainer control onto the form
(Note: right click the Toolbox, click items.. and then browse and select
Microsoft.Practices.CompositeUI.Winforms.dll)2. Drag a TabWorkSpace onto the form and drop it onto the left hand panel of the SplitContainer.
3. Right click the TabWorkSpace and click Remove Tab.
Creating and Showing the SmartPart
Create an Interface
1. Add a new Interface named IMyView.cs and make it public
public interface IMyViewCreate a SmartPart user control
{
event EventHandler Load;
string Message { get; set; }
}
1. Add a new User Control named MyView.cs
2. Drag a Label control
3. Derive the class Myview from IMyView
public partial class MyView : UserControl, IMyView4. Right-click IMyView and click Implement Interface.
5. Replace the two throw statements
public string MessageCreate a Presenter
{
get
{
return this.label1.Text;
}
set
{
this.label1.Text = value;
}
}
6. Create a new class named MyPresenter.cs and add a variable of type IMyView
public class MyPresenter7. Create a constructor for the class. The constructor takes a reference to the view, sets it as the view for this presenter, and subscribes to the Load event of the view
{
IMyView view;
public MyPresenter(IMyView view)8. Create an Event handler for the Load event. This sets the Message property of the Label control
{
this.view = view;
view.Load += new EventHandler(view_Load);
}
void view_Load(object sender, EventArgs e)Reference to the WorkItem
{
view.Message = "Hello World from a Module";
}
1. Open the MyModuleInit.cs and add a variable parentWorkItem. It reference to the root ShellWorkItem
private WorkItem parentWorkItem;
2. Add a public property to the class. It references the existing WorkItem, and passes back a reference to it.
3. Modify the Load method[ServiceDependency]
public WorkItem ParentWorkItem
{
set { parentWorkItem = value; }
}
public override void Load()
{
base.Load();
MyWorkItem myWorkItem = parentWorkItem.WorkItems.AddNew<MyWorkItem>();
myWorkItem.Run(parentWorkItem.Workspaces["tabWorkspace1"]);
}
Create and show the view
4. Open the file MyWorkItem.cs
using Microsoft.Practices.CompositeUI.SmartParts;5. Create a public Run method that accepts as a parameter a reference to the TabWorkspace (IWorkspace will let you change the type of workspace in future)
public void Run(IWorkspace TabWorkspace)6. Add statements to the Run method that create a new instance of the MyView class and a new instance of the MyPresenter class. Passing the view instance you just created to the presenter connects them together
{
}
IMyView view = this.Items.AddNew<MyView>();7. Add statements to the Run method that add the new presenter to the current WorkItem and call the Show method of the TabWorkspace to display the view.
MyPresenter presenter = new MyPresenter(view);
this.Items.Add(presenter);
TabWorkspace.Show(view);