纸上得来终觉浅,绝知此事要躬行。

 

WPF模版[DataTemplate]使用


1
GridViewColumn gvc = new GridViewColumn(); 2 3 // Binding很强大,但是不知道怎么解释。从使用中慢慢体会 4 Binding binding = new Binding(); 5 6 // 绑定到此模版的数据源的属性路径 7 binding.Path = new PropertyPath("SerialNo"); 8 9 // MSDN:描述数据对象的可视结构。 10 DataTemplate dtemplate = new DataTemplate(); 11 12 // 新建一个模版,参数说明这个模版依懒于哪个控件 13 FrameworkElementFactory fef = new FrameworkElementFactory(typeof(TextBlock)); 14 15 // 设置此模版对应的Binding对象 16 fef.SetBinding(TextBlock.TextProperty, binding); 17 18 // 设置此模版所对应控件的依懒属性 19 fef.SetValue(TextBlock.TextAlignmentProperty, TextAlignment.Right); 20 21 // 设置这个可视结构的模版 22 dtemplate.VisualTree = fef; 23 24 // 设置GridViewColumn的数据模版 25 gvc.CellTemplate = dtemplate;

posted on 2012-05-18 18:17  JRoger  阅读(396)  评论(0编辑  收藏  举报

导航