WPF后台生成datatemplate(TreeViewItem例子)
2013-07-16 16:42
549 查看
public void loadCheckListDataTemplate(TreeViewItem tvi)
{
DataTemplate cdt = new DataTemplate();
FrameworkElementFactory cfef = new FrameworkElementFactory(typeof(StackPanel));
cfef.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal);
Binding binding = new Binding();
FrameworkElementFactory subfef1 = new FrameworkElementFactory(typeof(TextBlock));
subfef1.SetValue(TextBlock.TextProperty, binding);
subfef1.SetValue(TextBlock.MarginProperty, new Thickness(0, 0, 5, 0));
cfef.AppendChild(subfef1);
FrameworkElementFactory subfef2 = new FrameworkElementFactory(typeof(CheckBox));
subfef2.SetValue(CheckBox.ContentProperty, "添加");
subfef2.SetValue(CheckBox.MarginProperty, new Thickness(0, 0, 5, 0));
cfef.AppendChild(subfef2);
FrameworkElementFactory subfef3 = new FrameworkElementFactory(typeof(CheckBox));
subfef3.SetValue(CheckBox.ContentProperty, "修改");
subfef3.SetValue(CheckBox.MarginProperty, new Thickness(0, 0, 5, 0));
cfef.AppendChild(subfef3);
FrameworkElementFactory subfef4 = new FrameworkElementFactory(typeof(CheckBox));
subfef4.SetValue(CheckBox.ContentProperty, "删除");
subfef4.SetValue(CheckBox.MarginProperty, new Thickness(0, 0, 5, 0));
cfef.AppendChild(subfef4);
cdt.VisualTree = cfef;
tvi.HeaderTemplate = cdt;
}
{
DataTemplate cdt = new DataTemplate();
FrameworkElementFactory cfef = new FrameworkElementFactory(typeof(StackPanel));
cfef.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal);
Binding binding = new Binding();
FrameworkElementFactory subfef1 = new FrameworkElementFactory(typeof(TextBlock));
subfef1.SetValue(TextBlock.TextProperty, binding);
subfef1.SetValue(TextBlock.MarginProperty, new Thickness(0, 0, 5, 0));
cfef.AppendChild(subfef1);
FrameworkElementFactory subfef2 = new FrameworkElementFactory(typeof(CheckBox));
subfef2.SetValue(CheckBox.ContentProperty, "添加");
subfef2.SetValue(CheckBox.MarginProperty, new Thickness(0, 0, 5, 0));
cfef.AppendChild(subfef2);
FrameworkElementFactory subfef3 = new FrameworkElementFactory(typeof(CheckBox));
subfef3.SetValue(CheckBox.ContentProperty, "修改");
subfef3.SetValue(CheckBox.MarginProperty, new Thickness(0, 0, 5, 0));
cfef.AppendChild(subfef3);
FrameworkElementFactory subfef4 = new FrameworkElementFactory(typeof(CheckBox));
subfef4.SetValue(CheckBox.ContentProperty, "删除");
subfef4.SetValue(CheckBox.MarginProperty, new Thickness(0, 0, 5, 0));
cfef.AppendChild(subfef4);
cdt.VisualTree = cfef;
tvi.HeaderTemplate = cdt;
}
相关文章推荐
- WPF使用HierarchicalDataTemplate绑定Dictionary生成TreeView
- WPF使用HierarchicalDataTemplate绑定Dictionary生成TreeView
- WPF中ControlTemplate,ItemsPanelTemplate ,DataTemplate
- WPF 数据模板DataType属性的使用,不用指定ItemTemplate
- WPF TreeView HierarchicalDataTemplate
- WPF中Treeview使用HierarchicalDataTemplate模板之后内容不充满
- WPF TreeView 后台C#选中指定的Item, 需要遍历
- 【WPF】ListBox使用DataTemplate 以及默认选中第一项Item
- WPF 深入浅出 模板(DataTemplate 数据外衣、ControlTemplate 控件外衣、ItemsPanelTemplate 项布局
- ControlTemplate,ItemsPanelTemplate,DataTemplate(wpf)
- Silverlight中TreeView,TreeViewItem,HierarchalDataTemplate的详细用法
- WPF TreeView 后台C#选中指定的Item, 需要遍历
- WPF新手之为HierarchicalDataTemplate生成的Item项添加事件
- WPF TreeView 后台C#选中指定的Item, 需要遍历
- WPF-控件-DataTemplate生成的控件
- WPF数据绑定(ItemTemplate和DataTemplate)
- 如何实现具有层次结构的 TreeView <四> (WPF/TreeView/Style/Template)
- WPF中如何使用C#创建DataTemplate数据模版
- wpf的treeview显示item时候不能stretch的一个解决办法
- WPF中自定义的DataTemplate中的控件,在Window_Loaded事件中加载机制初探