prism4 StockTrader RI 项目分析一些体会

StockTrader RI 代码分析也有一段时间了

刚从codeplex获取到源代码的时候,看得一头雾水,不知所云(因为之前没做过wpf的项目,看文档也静不下那心来看)

后来就想了个笨办法,模拟项目实现一个新的demo项目,从布局,加载组件入手!

这确实是一个好的办法,三下五除二,整个StockTrader RI的结构就清晰明了

首先项目需要启动,注入模块:

使用的是Mef实现

其代码在/StockTraderRI/StockTraderRIBootstrapper.cs

主要关注ConfigureAggregateCatalog方法的代码

 protected override void ConfigureAggregateCatalog()
        {
            this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(StockTraderRIBootstrapper).Assembly));
            this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(StockTraderRICommands).Assembly));
            this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(MarketModule).Assembly));
            this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(PositionModule).Assembly));
            this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(WatchModule).Assembly));
            this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(NewsModule).Assembly));
        }

 其次,关注Shell.xaml的布局

布局部分就得参考Prism4.chm文档的 Chapter 7: Composing the User Interface

借用文档的布局划分图

region的定义在 StockTraderRI.Infrastructure/RegionNames.cs

刚开始我没办法理解prism的各模块是如何组合,后来看了msdn 及博客园的文章,对mef有一定了解

就明白了,参考文章http://www.cnblogs.com/beniao/category/252120.html

剩下的就是靠个人阅读代码理解了.在我看来,通过shell显示总体布局,然后Modules实现具体的模块功能,使各模块解耦合

然后再具体剖析,一些有意思的实现,比如 TabItem的实现,ActionContent代码实现该位置的region激活(参考OrdersController,ShowOrdersView)

发现项目虽小,五脏俱全,了解了这个项目,对wpf就算入门了

转载于:https://www.cnblogs.com/wyxy2005/p/3359729.html

猜你喜欢

转载自blog.csdn.net/weixin_33840661/article/details/94510668
ri
今日推荐