2.3 WorkItem/SmartPart描述和实例
这里先了解WorkItem和SmartPart是什么东西?WorkItem是一个容器,在它里边可以放UI控件,SmartPart,各种服务和其他的组件,也可以嵌套WorkItem,所以放在父容器中的各种对象都可以在嵌套中的WorkItem获取以达到共享的目的。SmartPart就是每个功能模块的最小视图,如图2.3.1所看到的每个小块的视图就是一个SmartPart。
图2.3.1
1. 利用SCSF导航功能创建一个Module项目,如图2.3.2:
图2.3.2
图2.3.3
2. 在Views目录中利用SCSF生成三个VIEW视图分别为TestLeftView,TestMainView,UiElementView,(这里要说明一下,通过SCSF产生的VIEW都是按照MVP模式生产的)并在类WorkspaceNames增加相关代码:
public class WorkspaceNames { public const string LayoutWorkspace = "LayoutWorkspace"; public const string ModalWindows = "ModalWindows"; public const string LeftWorkspace = "LeftWorkspace"; public const string RightWorkspace = "RightWorkspace"; public const string LayoutUIElementView = "LayoutUIElementView"; } |
在ModuleController(继承于WorkItem)中增加下列代码:
public class ModuleController : WorkItemController { public override void Run() { AddViews(); } private void AddServices(){} private void ExtendMenu(){} private void ExtendToolStrip(){ }
private void AddViews() {
TestLeftView left = WorkItem.Items.AddNew<TestLeftView>(); WorkItem.Workspaces[WorkspaceNames.LeftWorkspace].Show(left);
TestMainView mainV = WorkItem.Items.AddNew<TestMainView>(); WorkItem.Workspaces[WorkspaceNames.RightWorkspace].Show(mainV);
WorkItem.Items.AddNew<ModuleActions>(); ActionCatalogService.Execute(ActionNames.ViewCustomerUIElement, WorkItem, this, null); ActionCatalogService.Execute(ActionNames.ShowCustomerUIElement, WorkItem, this, null);
} } |
其中的代码WorkItem.Workspaces[WorkspaceNames.RightWorkspace].Show(mainV)的作用就是把视图放在对应的WorkSpace中显示。
3. 运行并看结果
图2.3.4