Composite UI Application Block 初试

                                             初试Composite UI Application Block
Composite UI Application Block主要用来创建一个聚合的智能客户端解决方案,客户端可以由一组功能块构建而成。
一、用Composite UI 创建应用程序的一般步骤
        创建Shell
        创建Module
        创建对Services的引用
        创建和显示SmartParts
        用MVC和WorkItems开发
        创建定制的服务
        发布和订阅事件
        使用WorkItems
        显示UIElements
        注册Commands
    
    初次尝试仅创建Shell了,并使用了WorkItem和Controller。
        1.创建WinForm应用程序,添加一个主窗体Form1,在窗体中添加主菜单,并添加菜单项A ,B。分别生成菜单项A和B的点击事件.在窗体上添加DeckWorkspace
        2.修改Program类为非静态类,并让其继承FormShellApplication<WorkItem,Form1>。在Program中重写BeforeShellCreated和AfterShellCreated方法、方法体内分别调用了base.BeforeShellCreated()和base.AfterShellCreated() 、可以在调用基类的方法后再添加自己的代码。在Main内添加new Program().Run();
        3.创建自定义控件View1和View2,这两个自定义控件将被添加到主窗体的DeckWorkspace中。在类名上添加[SmartPart]
        4.创建MyWorkItem
        

    public class MyWorkItem : WorkItem
    {
        private View1 _view1;
        public void ShowView1(IWorkspace workspace)
        {
            if (_view1== null)
                _view1= this.Items.AddNew<View1 >("View1 ");
            workspace.Show(this._view1);  
        }

        private View2 _view2;
        public void ShowView2(IWorkspace workspace)
        {
            if (_view2== null)
                _view2= this.Items.AddNew<View2 >("View2");
            workspace.Show(this._view2);  
        }
    }

        5.创建MyController
        

    public class MyController : Controller
    {
        private WorkItem RootWorkItem
        {
            get { return base.WorkItem; }
        }

        private MyWorkItem _myWorkItem;
        public void ShowView1(IWorkspace workspace)
        {
            if (_myWorkItem==null)
                _myWorkItem = RootWorkItem.Items.AddNew<MyWorkItem>();
            _myWorkItem.ShowView1(workspace);
        }

        public void ShowView2(IWorkspace workspace)
        {
            if (_myWorkItem == null)
                _myWorkItem = RootWorkItem.Items.AddNew<MyWorkItem>();
            _myWorkItem.ShowView2(workspace);
        }
    }


        6.在Form1中注入MyController
                    private    MyController controller;
                    [CreateNew]
                    public     MyController Controller
                    {
                        set    {    controller=value;    }
                    }


        7.分别在A.B菜单事件中添加
                    controller.ShowView1(this.deckWorkspace1);
                    controller.ShowView2(this.deckWorkspace1);

你可能感兴趣的:(application)