[WPF]使用C#代码实现DataTemplate
2011-03-24 10:06
666 查看
/article/5542593.html
GridViewColumn column = new GridViewColumn();
GridViewColumnHeader h = new GridViewColumnHeader();
h.Content = "??????";
h.Tag = "*******";
column.Header = h;
DataTemplate dt = new DataTemplate();
FrameworkElementFactory fef = new FrameworkElementFactory(typeof(CheckBox));
Binding binding = new Binding();
binding.Path = new PropertyPath("MarketIndicator");
fef.SetBinding(CheckBox.ContentProperty, binding);
fef.SetValue(CheckBox.ForegroundProperty, Brushes.White);
dt.VisualTree = fef;
column.CellTemplate = dt;
(this.lvExecutionTable.View as GridView).Columns.Add(column);
http://hi.baidu.com/icexile/blog/item/2e75a73d47171108bba167e2.html
//内存中动态生成一个XAML,描述了一个DataTemplate
XNamespace ns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation";
XElement xDataTemplate =
new XElement( ns + "DataTemplate", new XAttribute( "xmlns", "http://schemas.microsoft.com/winfx/2006/xaml/presentation" ),
new XElement( ns + "TextBlock",
new XElement( ns + "TextBlock", new XAttribute( "Width", "100" ), new XAttribute( "Text", "{Binding Path=Name}" ) ),
new XElement( ns + "TextBlock", new XAttribute( "Width", "100" ), new XAttribute( "Text", "{Binding Path=Nick}" ) )
)
);
//将内存中的XAML实例化成为DataTemplate对象,并赋值给
//ListBox的ItemTemplate属性,完成数据绑定
XmlReader xr = xDataTemplate.CreateReader();
DataTemplate dataTemplate = XamlReader.Load( xr ) as DataTemplate;
lstBox_.ItemTemplate = dataTemplate;
//将两个TextBox分别绑定到当前Item的Name和Nick属性上
txtBoxName_.SetBinding( TextBox.TextProperty, "Name" );
txtBoxNick_.SetBinding( TextBox.TextProperty, "Nick" );
}
GridViewColumn column = new GridViewColumn();
GridViewColumnHeader h = new GridViewColumnHeader();
h.Content = "??????";
h.Tag = "*******";
column.Header = h;
DataTemplate dt = new DataTemplate();
FrameworkElementFactory fef = new FrameworkElementFactory(typeof(CheckBox));
Binding binding = new Binding();
binding.Path = new PropertyPath("MarketIndicator");
fef.SetBinding(CheckBox.ContentProperty, binding);
fef.SetValue(CheckBox.ForegroundProperty, Brushes.White);
dt.VisualTree = fef;
column.CellTemplate = dt;
(this.lvExecutionTable.View as GridView).Columns.Add(column);
http://hi.baidu.com/icexile/blog/item/2e75a73d47171108bba167e2.html
//内存中动态生成一个XAML,描述了一个DataTemplate
XNamespace ns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation";
XElement xDataTemplate =
new XElement( ns + "DataTemplate", new XAttribute( "xmlns", "http://schemas.microsoft.com/winfx/2006/xaml/presentation" ),
new XElement( ns + "TextBlock",
new XElement( ns + "TextBlock", new XAttribute( "Width", "100" ), new XAttribute( "Text", "{Binding Path=Name}" ) ),
new XElement( ns + "TextBlock", new XAttribute( "Width", "100" ), new XAttribute( "Text", "{Binding Path=Nick}" ) )
)
);
//将内存中的XAML实例化成为DataTemplate对象,并赋值给
//ListBox的ItemTemplate属性,完成数据绑定
XmlReader xr = xDataTemplate.CreateReader();
DataTemplate dataTemplate = XamlReader.Load( xr ) as DataTemplate;
lstBox_.ItemTemplate = dataTemplate;
//将两个TextBox分别绑定到当前Item的Name和Nick属性上
txtBoxName_.SetBinding( TextBox.TextProperty, "Name" );
txtBoxNick_.SetBinding( TextBox.TextProperty, "Nick" );
}
相关文章推荐
- WPF中如何使用C#创建DataTemplate数据模版
- [WPF]使用C#代码实现DataTemplate
- WPF关于C#代码实现Template
- C#里使用Oracle提供的Oracle.DataAccess 返回包里的记录集游标,含Oralce里的分页包代码
- C# Asp.net使用FormData对象实现ajax提交表单及上传图片
- 使用C#代码实现增加用户帐号
- 使用C#给PDF文档添加注释的实现代码
- c#使用Socket发送HTTP/HTTPS请求的实现代码
- [C#]使用 C# 代码实现拓扑排序 dotNet Core WEB程序使用 Nginx反向代理 C#里面获得应用程序的当前路径 关于Nginx设置端口号,在Asp.net 获取不到的,解决办法 .Net程序员 初学Ubuntu ,配置Nignix 夜深了,写了个JQuery的省市区三级级联效果
- C#中怎么使用系统默认浏览器打开指定的URL(代码实现)
- 使用C#调用系统API实现内存注入的代码
- C#如何不使用递归实现无限层次结构的代码分享[转]
- WPF and Silverlight 学习笔记(二十二):使用代码实现绑定、绑定数据的验证
- 进程通信之一 使用WM_COPYDATA C++及C#实现
- WPF使用HierarchicalDataTemplate绑定Dictionary生成TreeView
- WPF数据绑定(使用C#代码的方式)
- 在C#中使用Conditional元数据attribute来实现Debug代码
- C# 如何使用代码实现打开文件夹
- c#使用Lucene.net创建索引,实现搜索的代码示例
- cocos2d-x系列笔记(9.1)---浅谈cocos2d-x使用函数指针实现委托(上)---通过c#代码理解委托