创建一个带模版的用户控件 V.3

再重构此篇《创建一个带模版的用户控件  V.2http://www.cnblogs.com/insus/p/4164149.html 让其它动态实现header,Item和Footer。

Insus.NET不想所有代码写在InstantiateIn(Control container)方法内的switch分流上。其实是想使用开发设计模式的中介者(Mediator)来拆分它。

 

拆分为四个方法:
ListItemType.Header:


ListItemType.Item:


ListItemType.AlternatingItem:


ListItemType.Footer:

 
上面四个模板中,为了能动态列或是自定义一些程序,均对PlaceHolder容器委托DataBinding事件,Item和AlternatingItem是共用一个:



OK,现在可以实现中介者类:

 

现在就可以修改switch程序了,即是本篇第一张图片代码示例:

 
运行结果:


源代码下载:
http://download.cnblogs.com/insus/Refactoring/ref_mediator_repeater.rar

 

posted @ 2014-12-16 15:55  Insus.NET  阅读(910)  评论(0编辑  收藏  举报