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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值