三十七:采用用字符串构造DataTemplate实现CheckListBox的CustomControl
2008-01-30 09:26:24
版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://eallies.blog.51cto.com/375118/78992 |
为了方便大家学习,请单击此处下载该程序的代码。 这次Themes\CheckListBox.xaml的内容相当简单: 1 <ResourceDictionary
2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4 xmlns:local="clr-namespace:Eallies.OA.UI.Controls.Common">
5
6 <Style TargetType="{x:Type local:CheckListBox}" BasedOn="{StaticResource {x:Type ListBox}}" />
7
8 </ResourceDictionary> 1 protected override void OnInitialized(EventArgs e)
2 {
3 base.OnInitialized(e);
4
5 string template = string.Format("<DataTemplate xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"><CheckBox Name=\"chkCheckBox\" Tag=\"{{Binding Path={0}}}\" Content=\"{{Binding Path={1}}}\" /></DataTemplate>", this.ItemValuePath, this.ItemContentPath);
6 this.ItemTemplate = XamlReader.Load(XmlReader.Create(new StringReader(template))) as DataTemplate;
7 } 本文出自 “Denny_Zhang” 博客,请务必保留此出处http://eallies.blog.51cto.com/375118/78992 本文出自 51CTO.COM技术博客 |
附件下载:
程序代码
程序代码


Eallies
博客统计信息
热门文章
最新评论
友情链接