Create a Interface named IMyView.cs in the MyModule project and change as .
public interface IMyViewCreate a SmartPart user control
{
event EventHandler Load;
string Message { get; set; }
}
- add a User Control named MyView.cs
- Drag a Label control.
- Implement the IMyView interface
- add IMyView interface t othe class MyViewpublic partial class MyView : UserControl, IMyView 
- right-click IMyView and click Implement Interface, then click Implement Interface in the fly-out menu.
- modify property for Message in Interface.
public string Massage
{
get { return this.label1.Text;}
set { this.label1.Text = value;}
}
- Create a class named MyPresenter.cs
-  add a variable of type IMyViewpublic class MyPresenter 
 {
 IMyView view;
- Create a contructor for the classpublic MyPresenter(IMyView view) 
 {
 this.view = view;
 view.Load += new EventHandler(view_Load);
 }
- Create a event handler for the Load event
get a reference to the WorkItemvoid view_Load(object sender, EventArgs e)
{
view.Message = "Hello World from a Module";
}
- Open the MyModuleInit.cs add the following after the myCatalogService declaration.
 The variable will contain a reference to the root ShellWorkItemprivate WorkItem parentWorkItem; 
 [ServiceDependency]
 public WorkItem ParentWorkItem
 {
 set { parentWorkItem = value; }
 }
- Modify the load method.public override void Load() 
 {
 base.Load();
 MyWorkItem myWorkItem =
 parentWorkItem.WorkItems.AddNew<MyWorkItem>();
 myWorkItem.Run(parentWorkItem.Workspaces["tabWorkspace1"]);
 }
Create and show the view
- In MyWorkItem.cs, addusing Microsoft.Practices.CompositeUI.SmartParts; 
- Create a public Run method that accepts as a parameter a reference to the TabWorkspace.public void Run(IWorkspace TabWorkspace) 
 {
 IMyView view = this.Items.AddNew<MyView>();
 MyPresenter presenter = new MyPresenter(view);
 this.Items.Add(presenter);
 TabWorkspace.Show(view);
 }
 
No comments:
Post a Comment